Bump dev w/ eslint (#603)

* Bump dev w/ eslint

* Mop-up remaining lint issues

* Update stringShorten expectation
This commit is contained in:
Jaco Greeff
2020-05-23 14:23:13 +02:00
committed by GitHub
parent fd9ce319a5
commit 18a202c460
52 changed files with 436 additions and 352 deletions
+1 -13
View File
@@ -14,18 +14,6 @@ describe('stringShorten', (): void => {
it('returns the shortened value when > maxLength', (): void => {
expect(
stringShorten('0123456789', 3)
).toEqual('012..789');
});
it('returns undefined as undefined', (): void => {
expect(
stringShorten()
).toEqual('undefined');
});
it('returns non-string values as strings', (): void => {
expect(
stringShorten(12345678, 2)
).toEqual('12..78');
).toEqual('012…789');
});
});
+3 -5
View File
@@ -6,7 +6,7 @@
* @name stringShorten
* @summary Returns a string with maximum length
* @description
* Checks the string against the `prefixLength`, if longer than dopuble this, shortens it by placing `..` in the middle of it
* Checks the string against the `prefixLength`, if longer than double this, shortens it by placing `..` in the middle of it
* @example
* <BR>
*
@@ -17,12 +17,10 @@
* ```
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function stringShorten (_value?: any, prefixLength = 6): string {
const value = `${_value}`;
export default function stringShorten (value: string, prefixLength = 6): string {
if (value.length <= 2 + 2 * prefixLength) {
return value;
}
return `${value.substr(0, prefixLength)}..${value.slice(-prefixLength)}`;
return `${value.substr(0, prefixLength)}…${value.slice(-prefixLength)}`;
}