| Auto-Submit | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
played around with this. tried some variants. but in the end what you got here is solid. Nice work
it('trimEndWithMaxLength', () => {
const {trimEndWithMaxLength} = Platform.StringUtilities;
assert.strictEqual(trimEndWithMaxLength('aaa', 30), 'aaa');
assert.strictEqual(trimEndWithMaxLength('aaa', 3), 'aaa');
assert.strictEqual(trimEndWithMaxLength('aaa', 2), 'a…');
assert.strictEqual(trimEndWithMaxLength('aaa🥳', 4), 'aaa🥳');
assert.strictEqual(trimEndWithMaxLength('aaa🥳', 3), 'aa…');
assert.strictEqual(trimEndWithMaxLength('aaa👨👨👦👦', 4), 'aaa👨👨👦👦');
assert.strictEqual(trimEndWithMaxLength('aaa👨👨👦👦', 3), 'aa…');
assert.strictEqual(trimEndWithMaxLength('देवनागरी', 5), 'देवनागरी');
assert.strictEqual(trimEndWithMaxLength('देवनागरी', 4), 'देवना…');
assert.strictEqual(trimEndWithMaxLength('aaa', 3, ''), 'aaa');
assert.strictEqual(trimEndWithMaxLength('aaa', 2, ''), 'aa');
assert.strictEqual(trimEndWithMaxLength('aaa', 1), '…');
assert.strictEqual(trimEndWithMaxLength('aaa', 0), '…');
assert.strictEqual(trimEndWithMaxLength('aaaaa', 5, '...'), 'aaaaa');
assert.strictEqual(trimEndWithMaxLength('aaaaa', 4, '...'), 'a...');
assert.strictEqual(trimEndWithMaxLength('aaaaa', 3, '...'), '...');
assert.strictEqual(trimEndWithMaxLength('aaaaa', 1, '...'), '...');
// NFD.
assert.strictEqual(trimEndWithMaxLength('caf\u0065\u0301', 4), 'café');
assert.strictEqual(trimEndWithMaxLength('caf\u0065\u0301', 3), 'ca…');
});
i was fucking around and got explored some edge cases.. it resulted in this more comprehensive test suite.
and your fn passes all. :)
```suggestion
describe('trimEndWithMaxLength', () => {
const {trimEndWithMaxLength} = Platform.StringUtilities;
it('returns the original string if it fits within maxLength', () => {
assert.strictEqual(trimEndWithMaxLength('abc', 3), 'abc');
assert.strictEqual(trimEndWithMaxLength('abc', 10), 'abc');
assert.strictEqual(trimEndWithMaxLength('', 5), '');
}); it('trims the string and adds an ellipsis if it exceeds maxLength', () => {
assert.strictEqual(trimEndWithMaxLength('abc', 2), 'a…');
assert.strictEqual(trimEndWithMaxLength('abcdef', 5), 'abcd…');
}); it('returns just the ellipsis if maxLength is small', () => {
assert.strictEqual(trimEndWithMaxLength('abc', 1), '…');
assert.strictEqual(trimEndWithMaxLength('abc', 0), '…');
}); it('returns the empty string if the input is empty and maxLength is 0', () => {
// Logic check:
// str.length (0) <= maxLength (0) -> returns str ("")
assert.strictEqual(trimEndWithMaxLength('', 0), '');
}); it('handles unicode surrogate pairs and emojis correctly', () => {
assert.strictEqual(trimEndWithMaxLength('aaa🥳', 4), 'aaa🥳');
assert.strictEqual(trimEndWithMaxLength('aaa🥳', 3), 'aa…');
assert.strictEqual(trimEndWithMaxLength('aaa👨👨👦👦', 4), 'aaa👨👨👦👦');
assert.strictEqual(trimEndWithMaxLength('aaa👨👨👦👦', 3), 'aa…');
assert.strictEqual(trimEndWithMaxLength('🇺🇸🇨🇦', 2), '🇺🇸🇨🇦');
assert.strictEqual(trimEndWithMaxLength('🇺🇸🇨🇦', 1), '…');
}); it('handles NFD forms correctly', () => {
assert.strictEqual(trimEndWithMaxLength('caf\u0065\u0301', 4), 'café');
assert.strictEqual(trimEndWithMaxLength('caf\u0065\u0301', 3), 'ca…');
}); it('handles complex ZWJ sequences', () => {
const family = '👨👩👧👦'; // 1 grapheme
// "Start" (5) + Family (1) + "End" (3) = 9 graphemes.
assert.strictEqual(trimEndWithMaxLength(`Start${family}End`, 9), `Start${family}End`);
assert.strictEqual(trimEndWithMaxLength(`Start${family}End`, 8), `Start${family}E…`);
// Max 7. Keep 6 (7-1). "Start" (5) + Family (1).
assert.strictEqual(trimEndWithMaxLength(`Start${family}End`, 7), `Start${family}…`);
// "Start" (5) + Family (1) = 6.
// If limit is 6. "Start" + Family.
assert.strictEqual(trimEndWithMaxLength(`Start${family}`, 6), `Start${family}`);
// If limit is 5. "Star…".
assert.strictEqual(trimEndWithMaxLength(`Start${family}`, 5), 'Star…');
}); it('handles devanagari characters', () => {
assert.strictEqual(trimEndWithMaxLength('देवनागरी', 5), 'देवनागरी');
assert.strictEqual(trimEndWithMaxLength('देवनागरी', 4), 'देवना…');
});
});
```export const trimMiddle = (str: string, maxLength: number, ellipsis = '…'): string => {lets remove this as a param. it's unused in the codebase.
(and moreso.. because if you want to use a flag emoji as an ellipsis character.. you have a few bugs now. )
export const trimEndWithMaxLength = (str: string, maxLength: number, ellipsis = '…'): string => {same remove
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |