generated from graasp/graasp-repo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { applyEllipsisOnLength } from './string.js'; | ||
|
||
describe('applyEllipsisOnLength', () => { | ||
it('does not add ellipsis', () => { | ||
expect(applyEllipsisOnLength('mystring', 100)).toEqual('mystring'); | ||
expect(applyEllipsisOnLength('my very long string is here', 100)).toEqual( | ||
'my very long string is here', | ||
); | ||
}); | ||
it('add ellipsis', () => { | ||
expect(applyEllipsisOnLength('mystring', 2)).toEqual('my…'); | ||
expect(applyEllipsisOnLength('my very long string is here', 10)).toEqual( | ||
'my very lo…', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* add ellipsis on string given length | ||
* warning: use css instead of this function if possible | ||
* @param {any} longString:string | ||
* @param {any} maxLength:number | ||
* @returns {any} | ||
*/ | ||
export const applyEllipsisOnLength = ( | ||
longString: string, | ||
maxLength: number, | ||
): string => | ||
`${longString.slice(0, maxLength)}${ | ||
(longString.length || 0) > maxLength ? '…' : '' | ||
}`; |