1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.stringShorten = void 0;
|
4 | /**
|
5 | * @name stringShorten
|
6 | * @summary Returns a string with maximum length
|
7 | * @description
|
8 | * Checks the string against the `prefixLength`, if longer than double this, shortens it by placing `..` in the middle of it
|
9 | * @example
|
10 | * <BR>
|
11 | *
|
12 | * ```javascript
|
13 | * import { stringShorten } from '@polkadot/util';
|
14 | *
|
15 | * stringShorten('1234567890', 2); // => 12..90
|
16 | * ```
|
17 | */
|
18 | function stringShorten(value, prefixLength = 6) {
|
19 | return value.length <= 2 + 2 * prefixLength
|
20 | ? value.toString()
|
21 | : `${value.substring(0, prefixLength)}…${value.slice(-prefixLength)}`;
|
22 | }
|
23 | exports.stringShorten = stringShorten;
|