1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.stringShorten = stringShorten;
|
7 |
|
8 | // Copyright 2017-2022 @polkadot/util authors & contributors
|
9 | // SPDX-License-Identifier: Apache-2.0
|
10 |
|
11 | /**
|
12 | * @name stringShorten
|
13 | * @summary Returns a string with maximum length
|
14 | * @description
|
15 | * Checks the string against the `prefixLength`, if longer than double this, shortens it by placing `..` in the middle of it
|
16 | * @example
|
17 | * <BR>
|
18 | *
|
19 | * ```javascript
|
20 | * import { stringShorten } from '@polkadot/util';
|
21 | *
|
22 | * stringShorten('1234567890', 2); // => 12..90
|
23 | * ```
|
24 | */
|
25 | function stringShorten(value) {
|
26 | let prefixLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
|
27 | return value.length <= 2 + 2 * prefixLength ? value.toString() : `${value.substring(0, prefixLength)}…${value.slice(-prefixLength)}`;
|
28 | } |
\ | No newline at end of file |