/**
* Returns a string object with various string manipulation functions.
* @param {string} string - The input string.
* @returns {StringFunctions}
*/
export function string(string) {
let fn = () => {};
/**
* @memberof StringFunctions.prototype
* @returns {boolean} True if the string is a string, false otherwise.
* @inner
*/
fn.prototype.isString = function () {
return typeof string === 'string'
}
fn.prototype.capitalize = function () {
return (string.toLowerCase()).replace(/(?:^|\s|["'([{])+\S/g, match => match.toUpperCase());
}
fn.prototype.toCamelCase = function () {
return string.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
}).replace(/\s+/g, '');
}
fn.prototype.toSnakeCase = function () {
return string && string.match(
/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map(s => s.toLowerCase())
.join('_');
}
fn.prototype.toKebabCase = function () {
return string
.replace(/([a-z])([A-Z])/g, "$1-$2")
.replace(/[\s_]+/g, '-')
.toLowerCase();
}
fn.prototype.toPascalCase = function () {
return (' ' + string).toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => {
return chr.toUpperCase()
});
}
fn.prototype.toLowerCase = function () {
return string.toLowerCase()
}
fn.prototype.toUpperCase = function () {
return string.toUpperCase()
}
fn.prototype.firstNChars = function (n = 10) {
return string.slice(0, n);
}
fn.prototype.lastNChars = function (n = 10) {
return string.slice(-n);
}
return new fn();
}`
我得到以下定义(.d.ts) 我想获取有关所有子函数或嵌套函数的类型化信息
/**
* Returns a string object with various string manipulation functions.
* @param {string} string - The input string.
* @returns {StringFunctions}
*/
export function string(string: string): StringFunctions;