UNPKG

@bemedev/types

Version:

Type definitions for Bemedev projects

89 lines (86 loc) 2.71 kB
import { castFn, expandFn, _unknown } from '../utils.js'; import { ENGLISH_LETTERS } from '../constants/strings.js'; const strings = castFn()({ is: expandFn((value) => { return typeof value === 'string'; }, { // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types instance: (value) => { return value instanceof String; }, }), type: String, getLength: (value) => { const out = value.length; return _unknown(out); }, startsWith: (value, prefix) => { return typeof value === 'string' && value.startsWith(prefix); }, endsWith: (value, suffix) => { return typeof value === 'string' && value.endsWith(suffix); }, includes: (value, ...segments) => { if (typeof value !== 'string') return false; // Check if the string contains any of the segments for (const seg of segments) { if (value.includes(seg)) { return true; } } return false; }, contains: (value, ...segments) => strings.includes(value, ...segments), toLowerCase: (value) => { const out = value.toLowerCase(); return _unknown(out); }, toUpperCase: (value) => { const out = value.toUpperCase(); return _unknown(out); }, letters: castFn()({ is: (value) => { if (typeof value !== 'string') return false; if (value.length === 0) return false; // Check if all characters are English letters for (const char of value.toLowerCase()) { if (!ENGLISH_LETTERS.includes(char)) { return false; } } return true; }, lower: castFn()({ is: (value) => { return (typeof value === 'string' && strings.letters.is(value) && value === value.toLowerCase()); }, }), upper: castFn()({ is: (value) => { return (typeof value === 'string' && strings.letters.is(value) && value === value.toUpperCase()); }, }), }), add: (value, before = '', after = '') => { const out = `${before}${value}${after}`; return _unknown(out); }, join: (sep = ' ', ...args) => { const out = args.join(sep); return _unknown(out); }, splitBy: (value, by = '.') => { const out = value.split(by); return _unknown(out); }, }); export { strings }; //# sourceMappingURL=strings.js.map