mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 04:27:59 +00:00
23 lines
693 B
JavaScript
23 lines
693 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.stringShorten = stringShorten;
|
|
/**
|
|
* @name stringShorten
|
|
* @summary Returns a string with maximum length
|
|
* @description
|
|
* Checks the string against the `prefixLength`, if longer than double this, shortens it by placing `..` in the middle of it
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* import { stringShorten } from '@pezkuwi/util';
|
|
*
|
|
* stringShorten('1234567890', 2); // => 12..90
|
|
* ```
|
|
*/
|
|
function stringShorten(value, prefixLength = 6) {
|
|
return value.length <= 2 + 2 * prefixLength
|
|
? value.toString()
|
|
: `${value.substring(0, prefixLength)}…${value.slice(-prefixLength)}`;
|
|
}
|