@bemedev/types
Version:
Type definitions for Bemedev projects
91 lines (87 loc) • 2.79 kB
JavaScript
;
var utils = require('../utils.cjs');
var constants_strings = require('../constants/strings.cjs');
const strings = utils.castFn()({
is: utils.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 utils._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 utils._unknown(out);
},
toUpperCase: (value) => {
const out = value.toUpperCase();
return utils._unknown(out);
},
letters: utils.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 (!constants_strings.ENGLISH_LETTERS.includes(char)) {
return false;
}
}
return true;
},
lower: utils.castFn()({
is: (value) => {
return (typeof value === 'string' &&
strings.letters.is(value) &&
value === value.toLowerCase());
},
}),
upper: utils.castFn()({
is: (value) => {
return (typeof value === 'string' &&
strings.letters.is(value) &&
value === value.toUpperCase());
},
}),
}),
add: (value, before = '', after = '') => {
const out = `${before}${value}${after}`;
return utils._unknown(out);
},
join: (sep = ' ', ...args) => {
const out = args.join(sep);
return utils._unknown(out);
},
splitBy: (value, by = '.') => {
const out = value.split(by);
return utils._unknown(out);
},
});
exports.strings = strings;
//# sourceMappingURL=strings.cjs.map