@synstack/str 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/str.index.ts","../src/str.chainable.ts","../src/str.lib.ts"],"sourcesContent":["export {\n camelCase,\n capitalCase,\n constantCase,\n dotCase,\n kebabCase,\n noCase,\n pascalCase,\n pascalSnakeCase,\n pathCase,\n sentenceCase,\n snakeCase,\n trainCase,\n} from \"change-case\";\nexport { Str, str } from \"./str.chainable.ts\";\nexport * from \"./str.lib.ts\";\n","import { Pipeable } from \"@synstack/pipe\";\nimport * as changeCase from \"change-case\";\nimport { type Stringable } from \"../../shared/src/ts.utils.ts\";\nimport * as lib from \"./str.lib.ts\";\n\nexport class Str extends Pipeable<Str, string> {\n private readonly text: string;\n\n public constructor(text: string) {\n super();\n this.text = text;\n }\n\n public valueOf(): string {\n return this.text;\n }\n\n public toString() {\n return this.text;\n }\n\n public instanceOf(): Str {\n return this;\n }\n\n /**\n * Remove empty lines at the start of the text but leave whitespace on the first line with content\n */\n public chopEmptyLinesStart() {\n return new Str(lib.chopEmptyLinesStart(this.text));\n }\n\n /**\n * Remove empty lines at the end of the text but leave whitespace on the last line with content\n */\n public chopEmptyLinesEnd() {\n return new Str(lib.chopEmptyLinesEnd(this.text));\n }\n\n /**\n * Remove all space (\\s) characters in lines without content\n */\n public trimEmptyLines() {\n return new Str(lib.trimEmptyLines(this.text));\n }\n\n /**\n * Remove all spaces (\\s) characters at the end of lines\n */\n public trimLinesTrailingSpaces() {\n return new Str(lib.trimLinesTrailingSpaces(this.text));\n }\n\n /**\n * Removes the leading and trailing white space and line terminator characters\n */\n public trim() {\n return new Str(lib.trim(this.text));\n }\n\n /**\n * Removes the leading white space and line terminator characters\n */\n public trimStart() {\n return new Str(lib.trimStart(this.text));\n }\n\n /**\n * Removes the trailing white space and line terminator characters\n */\n public trimEnd() {\n return new Str(lib.trimEnd(this.text));\n }\n\n /**\n * Split a string into substrings using the specified separator and return them as an array\n */\n public split(separator: string | RegExp, limit?: number) {\n return lib.split(this.text, separator, limit).map((v) => new Str(v));\n }\n\n /**\n * Add line numbers to a string\n * @param separator The separator to use between the line number and the line content.\n * Defaults to \":\"\n */\n public addLineNumbers(separator: string = \":\") {\n return new Str(lib.addLineNumbers(this.text, separator));\n }\n\n /**\n * Returns the character at the specified index\n * @return string or undefined if the index is out of bounds\n */\n public at(index: number) {\n return this.text.at(index);\n }\n\n /**\n * Returns the length of the string\n */\n public length() {\n return this.text.length;\n }\n\n /**\n * Indent the string by the specified number of spaces\n * @param size The number of spaces to indent by\n * @param char The character to use for indentation. Defaults to \" \"\n */\n public indent(size: number, char: string = \" \") {\n return new Str(lib.indent(this.text, size, char));\n }\n\n /**\n * Dedent the string by the specified number of spaces\n * @param indentation The number of spaces to dedent by.\n * If not provided, it will be calculated automatically based on the maximum indentation in the string.\n */\n public dedent(indentation?: number) {\n return new Str(lib.dedent(this.text, indentation));\n }\n\n /**\n * Chop the string at the start by the specified number of characters\n */\n public chopStart(count: number) {\n return new Str(lib.chopStart(this.text, count));\n }\n\n /**\n * Chop the string at the end by the specified number of characters\n */\n public chopEnd(count: number) {\n if (count === 0) return this;\n return new Str(lib.chopEnd(this.text, count));\n }\n\n /**\n * Remove successive newlines of the specified repetition or more\n * @param maxRepeat the maximum number of newlines to allow\n */\n public chopRepeatNewlines(maxRepeat: number) {\n if (maxRepeat === 0) return this;\n return new Str(lib.chopRepeatNewlines(this.text, maxRepeat));\n }\n\n /**\n * Take the first n characters of the string\n */\n public takeStart(count: number) {\n return new Str(lib.takeStart(this.text, count));\n }\n\n /**\n * Take the last n characters of the string\n */\n public takeEnd(count: number) {\n return new Str(lib.takeEnd(this.text, count));\n }\n\n /**\n * Returns the last line of the string\n */\n public lastLine() {\n return new Str(lib.lastLine(this.text));\n }\n\n /**\n * Returns the first line of the string\n */\n public firstLine() {\n return new Str(lib.firstLine(this.text));\n }\n\n /**\n * Returns the number of leading spaces in the string\n */\n public leadingSpacesCount() {\n return lib.leadingSpacesCount(this.text);\n }\n\n /**\n * Returns the indentation level of the string skipping empty lines in the process\n */\n public indentation() {\n return lib.indentation(this.text);\n }\n\n /**\n * Returns true if the string is empty or contains only whitespace\n */\n public isEmpty() {\n return lib.isEmpty(this.text);\n }\n\n /**\n * Converts the string to camel case\n */\n public camelCase() {\n return new Str(changeCase.camelCase(this.text));\n }\n\n /**\n * Converts the string to capital case\n */\n public capitalCase() {\n return new Str(changeCase.capitalCase(this.text));\n }\n\n /**\n * Converts the string to constant case\n */\n public constantCase() {\n return new Str(changeCase.constantCase(this.text));\n }\n\n /**\n * Converts the string to dot case\n */\n public dotCase() {\n return new Str(changeCase.dotCase(this.text));\n }\n\n /**\n * Converts the string to kebab case\n */\n public kebabCase() {\n return new Str(changeCase.kebabCase(this.text));\n }\n\n /**\n * Converts the string to no case\n */\n public noCase() {\n return new Str(changeCase.noCase(this.text));\n }\n\n /**\n * Converts the string to pascal case\n */\n public pascalCase() {\n return new Str(changeCase.pascalCase(this.text));\n }\n\n /**\n * Converts the string to pascal snake case\n */\n public pascalSnakeCase() {\n return new Str(changeCase.pascalSnakeCase(this.text));\n }\n\n /**\n * Converts the string to path case\n */\n public pathCase() {\n return new Str(changeCase.pathCase(this.text));\n }\n\n /**\n * Converts the string to sentence case\n */\n public sentenceCase() {\n return new Str(changeCase.sentenceCase(this.text));\n }\n\n /**\n * Converts the string to snake case\n */\n public snakeCase() {\n return new Str(changeCase.snakeCase(this.text));\n }\n\n /**\n * Converts the string to train case\n */\n public trainCase() {\n return new Str(changeCase.trainCase(this.text));\n }\n\n /**\n * Shorthand for `.toString()`\n */\n public get str() {\n return this.toString();\n }\n}\n\nexport const str = (text: Stringable) => {\n return new Str(text.toString());\n};\n","/**\n * Remove empty lines at the start of the text but leave whitespace on the first line with content\n */\nexport const chopEmptyLinesStart = (text: string) => {\n return text.replace(/^(\\s*\\n)+/, \"\");\n};\n\n/**\n * Remove empty lines at the end of the text but leave whitespace on the last line with content\n */\nexport const chopEmptyLinesEnd = (text: string) => {\n return text.replace(/(\\n\\s*)+$/, \"\");\n};\n\n/**\n * Remove all space (\\s) characters in lines without content\n */\nexport const trimEmptyLines = (text: string) => {\n return text.replace(/(^|\\n)\\s+(\\n|$)/g, \"$1$2\");\n};\n\n/**\n * Remove all space (\\s) characters at the end of lines\n */\nexport const trimLinesTrailingSpaces = (text: string) => {\n return text.replace(/ +(\\n|$)/g, \"$1\");\n};\n\n/**\n * Removes the leading and trailing white space and line terminator characters\n */\nexport const trim = (text: string) => {\n return text.trim();\n};\n\n/**\n * Removes the leading white space and line terminator characters\n */\nexport const trimStart = (text: string) => {\n return text.trimStart();\n};\n\n/**\n * Removes the trailing white space and line terminator characters\n */\nexport const trimEnd = (text: string) => {\n return text.trimEnd();\n};\n\n/**\n * Split a string into substrings using the specified separator and return them as an array\n */\nexport const split = (\n text: string,\n separator: string | RegExp,\n limit?: number,\n) => {\n return text.split(separator, limit);\n};\n\n/**\n * Add line numbers to a string\n * @param text The string to add line numbers to\n * @param separator The separator to use between the line number and the line content.\n * Defaults to \":\"\n */\nexport const addLineNumbers = (text: string, separator: string = \":\") => {\n return text\n .split(\"\\n\")\n .map((line, index) => `${index}${separator}${line}`)\n .join(\"\\n\");\n};\n\n/**\n * Returns the indentation level of the string skipping empty lines in the process\n */\nexport const indentation = (text: string) => {\n return (\n text.split(\"\\n\").reduce((acc: number | null, line) => {\n if (line.trim() === \"\") return acc;\n const indentation = leadingSpacesCount(line);\n if (acc === null) return indentation;\n return Math.min(acc, indentation);\n }, null) ?? 0\n );\n};\n\n/**\n * Indent the string by the specified number of spaces\n * @param size The number of spaces to indent by\n * @param char The character to use for indentation. Defaults to \" \"\n */\nexport const indent = (text: string, size: number, char: string = \" \") => {\n if (size === 0) return text;\n\n const indentStr = char.repeat(size);\n return text\n .split(\"\\n\")\n .map((line) => indentStr + line)\n .join(\"\\n\");\n};\n\n/**\n * Dedent the string by the specified number of spaces\n * @param indentation The number of spaces to dedent by.\n * If not provided, it will be calculated automatically based on the maximum indentation in the string.\n */\nexport const dedent = (text: string, size?: number) => {\n const _size = size ?? indentation(text);\n if (_size === 0) return text;\n const regex = new RegExp(`^\\\\s{1,${_size}}`);\n return text\n .split(\"\\n\")\n .map((line) => line.replace(regex, \"\"))\n .join(\"\\n\");\n};\n\n/**\n * Chop the string at the end by the specified number of characters\n */\nexport const chopEnd = (text: string, count: number) => {\n if (count === 0) return text;\n return text.slice(0, -count);\n};\n\n/**\n * Chop the string at the start by the specified number of characters\n */\nexport const chopStart = (text: string, count: number) => {\n if (count === 0) return text;\n return text.slice(count);\n};\n\n/**\n * Remove successive newlines of the specified repetition or more\n * @param maxRepeat the maximum number of newlines to allow\n */\nexport const chopRepeatNewlines = (text: string, maxRepeat: number) => {\n if (maxRepeat === 0) return text;\n return text.replace(\n new RegExp(`\\n{${maxRepeat + 1},}`, \"g\"),\n \"\\n\".repeat(maxRepeat),\n );\n};\n\n/**\n * Take the first n characters of the string\n */\nexport const takeStart = (text: string, count: number) => {\n return text.slice(0, count);\n};\n\n/**\n * Take the last n characters of the string\n */\nexport const takeEnd = (text: string, count: number) => {\n return text.slice(-count);\n};\n\n/**\n * Returns the last line of the string\n */\nexport const lastLine = (text: string) => {\n return text.split(\"\\n\").at(-1) ?? \"\";\n};\n\n/**\n * Returns the first line of the string\n */\nexport const firstLine = (text: string) => {\n return text.split(\"\\n\").at(0) ?? \"\";\n};\n\n/**\n * Returns the number of leading spaces in the string\n */\nexport const leadingSpacesCount = (text: string) => {\n return text.match(/^\\s+/)?.at(0)?.length ?? 0;\n};\n\n/**\n * Returns true if the string is empty or contains only whitespace\n */\nexport const isEmpty = (text: string) => {\n return text.trim() === \"\";\n};\n"],"mappings":";AAAA;AAAA,EACE,aAAAA;AAAA,EACA,eAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,UAAAC;AAAA,EACA,cAAAC;AAAA,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BAAS,KAAK,IAAI,CAAC;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA,EAKO,eAAe;AACpB,WAAO,IAAI,KAAe,wBAAa,KAAK,IAAI,CAAC;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA,EAKO,YAAY;AACjB,WAAO,IAAI,KAAe,qBAAU,KAAK,IAAI,CAAC;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKO,YAAY;AACjB,WAAO,IAAI,KAAe,qBAAU,KAAK,IAAI,CAAC;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKA,IAAW,MAAM;AACf,WAAO,KAAK,SAAS;AAAA,EACvB;AACF;AAEO,IAAM,MAAM,CAAC,SAAqB;AACvC,SAAO,IAAI,IAAI,KAAK,SAAS,CAAC;AAChC;","names":["camelCase","capitalCase","constantCase","dotCase","kebabCase","noCase","pascalCase","pascalSnakeCase","pathCase","sentenceCase","snakeCase","trainCase","indentation","indentation"]}
1
+ {"version":3,"sources":["../src/str.index.ts","../src/str.chainable.ts","../src/str.lib.ts"],"sourcesContent":["export {\n camelCase,\n capitalCase,\n constantCase,\n dotCase,\n kebabCase,\n noCase,\n pascalCase,\n pascalSnakeCase,\n pathCase,\n sentenceCase,\n snakeCase,\n trainCase,\n} from \"change-case\";\nexport { Str, str } from \"./str.chainable.ts\";\nexport * from \"./str.lib.ts\";\n","import { Pipeable } from \"@synstack/pipe\";\nimport * as changeCase from \"change-case\";\nimport { type Stringable } from \"../../shared/src/ts.utils.ts\";\nimport * as lib from \"./str.lib.ts\";\n\n/**\n * A chainable string manipulation class that extends Pipeable\n * Provides a fluent interface for string operations with full TypeScript support\n *\n * @example\n * ```typescript\n * import { str } from '@synstack/str'\n *\n * // Basic chaining\n * const result = str('Hello World')\n * .trim()\n * .split(' ')\n * .at(0)\n * .$\n *\n * // Advanced chaining with Pipeable methods\n * const modified = str('hello-world')\n * ._((s) => s.camelCase())\n * ._$((value) => value.toUpperCase())\n * .$\n * ```\n */\nexport class Str extends Pipeable<Str, string> {\n private readonly text: string;\n\n /**\n * Create a new Str instance\n * @param text - The input string to wrap\n * @example\n * ```typescript\n * const s = new Str('Hello World')\n * // or use the convenience function\n * const s = str('Hello World')\n * ```\n */\n public constructor(text: string) {\n super();\n this.text = text;\n }\n\n /**\n * Get the underlying string value\n * @returns The wrapped string value\n */\n public valueOf(): string {\n return this.text;\n }\n\n /**\n * Convert the Str instance to a string\n * @returns The wrapped string value\n */\n public toString() {\n return this.text;\n }\n\n /**\n * Get the current Str instance\n * @returns The current Str instance\n * @internal Used by Pipeable\n */\n public instanceOf(): Str {\n return this;\n }\n\n /**\n * Remove empty lines at the start of the text\n * @returns A new Str instance with empty lines removed from the start\n * @example\n * ```typescript\n * str('\\n\\n Hello').chopEmptyLinesStart().$ // ' Hello'\n * ```\n */\n public chopEmptyLinesStart() {\n return new Str(lib.chopEmptyLinesStart(this.text));\n }\n\n /**\n * Remove empty lines at the end of the text\n * @returns A new Str instance with empty lines removed from the end\n * @example\n * ```typescript\n * str('Hello\\n\\n').chopEmptyLinesEnd().$ // 'Hello'\n * ```\n */\n public chopEmptyLinesEnd() {\n return new Str(lib.chopEmptyLinesEnd(this.text));\n }\n\n /**\n * Remove whitespace from empty lines\n * @returns A new Str instance with whitespace removed from empty lines\n * @example\n * ```typescript\n * str('Hello\\n \\nWorld').trimEmptyLines().$ // 'Hello\\n\\nWorld'\n * ```\n */\n public trimEmptyLines() {\n return new Str(lib.trimEmptyLines(this.text));\n }\n\n /**\n * Remove trailing spaces from all lines\n * @returns A new Str instance with trailing spaces removed from all lines\n * @example\n * ```typescript\n * str('Hello \\nWorld ').trimLinesTrailingSpaces().$ // 'Hello\\nWorld'\n * ```\n */\n public trimLinesTrailingSpaces() {\n return new Str(lib.trimLinesTrailingSpaces(this.text));\n }\n\n /**\n * Remove leading and trailing whitespace\n * @returns A new Str instance with whitespace removed from both ends\n * @example\n * ```typescript\n * str(' Hello ').trim().$ // 'Hello'\n * ```\n */\n public trim() {\n return new Str(lib.trim(this.text));\n }\n\n /**\n * Remove leading whitespace\n * @returns A new Str instance with leading whitespace removed\n * @example\n * ```typescript\n * str(' Hello ').trimStart().$ // 'Hello '\n * ```\n */\n public trimStart() {\n return new Str(lib.trimStart(this.text));\n }\n\n /**\n * Remove trailing whitespace\n * @returns A new Str instance with trailing whitespace removed\n * @example\n * ```typescript\n * str(' Hello ').trimEnd().$ // ' Hello'\n * ```\n */\n public trimEnd() {\n return new Str(lib.trimEnd(this.text));\n }\n\n /**\n * Split the string into an array of Str instances\n * @param separator - String or RegExp to split on\n * @param limit - Maximum number of splits to perform\n * @returns Array of Str instances\n * @example\n * ```typescript\n * str('a,b,c').split(',') // [Str('a'), Str('b'), Str('c')]\n * str('a b c').split(' ', 2) // [Str('a'), Str('b')]\n * ```\n */\n public split(separator: string | RegExp, limit?: number) {\n return lib.split(this.text, separator, limit).map((v) => new Str(v));\n }\n\n /**\n * Add line numbers to each line\n * @param separator - String to separate line numbers from content\n * @returns A new Str instance with line numbers added\n * @example\n * ```typescript\n * str('A\\nB').addLineNumbers().$ // '0:A\\n1:B'\n * str('A\\nB').addLineNumbers(' -> ').$ // '0 -> A\\n1 -> B'\n * ```\n */\n public addLineNumbers(separator: string = \":\") {\n return new Str(lib.addLineNumbers(this.text, separator));\n }\n\n /**\n * Get the character at a specific index\n * @param index - Zero-based position in the string\n * @returns The character at the index, or undefined if out of bounds\n * @example\n * ```typescript\n * str('Hello').at(0) // 'H'\n * str('Hello').at(-1) // 'o'\n * ```\n */\n public at(index: number) {\n return this.text.at(index);\n }\n\n /**\n * Get the length of the string\n * @returns The number of characters in the string\n * @example\n * ```typescript\n * str('Hello').length() // 5\n * str('').length() // 0\n * ```\n */\n public length() {\n return this.text.length;\n }\n\n /**\n * Indent each line by a specified number of spaces\n * @param size - Number of spaces to add\n * @param char - Character to use for indentation\n * @returns A new Str instance with added indentation\n * @example\n * ```typescript\n * str('Hello\\nWorld').indent(2).$ // ' Hello\\n World'\n * str('A\\nB').indent(2, '-').$ // '--A\\n--B'\n * ```\n */\n public indent(size: number, char: string = \" \") {\n return new Str(lib.indent(this.text, size, char));\n }\n\n /**\n * Remove indentation from each line\n * @param indentation - Optional number of spaces to remove\n * @returns A new Str instance with indentation removed\n * @example\n * ```typescript\n * str(' Hello\\n World').dedent().$ // 'Hello\\n World'\n * str(' A\\n B').dedent(2).$ // ' A\\nB'\n * ```\n */\n public dedent(indentation?: number) {\n return new Str(lib.dedent(this.text, indentation));\n }\n\n /**\n * Remove characters from the start of the string\n * @param count - Number of characters to remove\n * @returns A new Str instance with characters removed from the start\n * @example\n * ```typescript\n * str('Hello').chopStart(2).$ // 'llo'\n * ```\n */\n public chopStart(count: number) {\n return new Str(lib.chopStart(this.text, count));\n }\n\n /**\n * Remove characters from the end of the string\n * @param count - Number of characters to remove\n * @returns A new Str instance with characters removed from the end\n * @example\n * ```typescript\n * str('Hello').chopEnd(2).$ // 'Hel'\n * ```\n */\n public chopEnd(count: number) {\n if (count === 0) return this;\n return new Str(lib.chopEnd(this.text, count));\n }\n\n /**\n * Limit consecutive newlines to a maximum count\n * @param maxRepeat - Maximum number of consecutive newlines to allow\n * @returns A new Str instance with limited consecutive newlines\n * @example\n * ```typescript\n * str('A\\n\\n\\nB').chopRepeatNewlines(1).$ // 'A\\nB'\n * str('A\\n\\n\\nB').chopRepeatNewlines(2).$ // 'A\\n\\nB'\n * ```\n */\n public chopRepeatNewlines(maxRepeat: number) {\n if (maxRepeat === 0) return this;\n return new Str(lib.chopRepeatNewlines(this.text, maxRepeat));\n }\n\n /**\n * Take characters from the start of the string\n * @param count - Number of characters to take\n * @returns A new Str instance with the first n characters\n * @example\n * ```typescript\n * str('Hello').takeStart(2).$ // 'He'\n * ```\n */\n public takeStart(count: number) {\n return new Str(lib.takeStart(this.text, count));\n }\n\n /**\n * Take characters from the end of the string\n * @param count - Number of characters to take\n * @returns A new Str instance with the last n characters\n * @example\n * ```typescript\n * str('Hello').takeEnd(2).$ // 'lo'\n * ```\n */\n public takeEnd(count: number) {\n return new Str(lib.takeEnd(this.text, count));\n }\n\n /**\n * Get the last line of the string\n * @returns A new Str instance containing the last line\n * @example\n * ```typescript\n * str('Hello\\nWorld').lastLine().$ // 'World'\n * ```\n */\n public lastLine() {\n return new Str(lib.lastLine(this.text));\n }\n\n /**\n * Get the first line of the string\n * @returns A new Str instance containing the first line\n * @example\n * ```typescript\n * str('Hello\\nWorld').firstLine().$ // 'Hello'\n * ```\n */\n public firstLine() {\n return new Str(lib.firstLine(this.text));\n }\n\n /**\n * Count leading space characters\n * @returns The number of leading space characters\n * @example\n * ```typescript\n * str(' Hello').leadingSpacesCount() // 2\n * str('Hello').leadingSpacesCount() // 0\n * ```\n */\n public leadingSpacesCount() {\n return lib.leadingSpacesCount(this.text);\n }\n\n /**\n * Get the minimum indentation level of non-empty lines\n * @returns The number of spaces in the minimum indentation\n * @example\n * ```typescript\n * str(' Hello\\n World').indentation() // 2\n * str('Hello\\n World').indentation() // 0\n * ```\n */\n public indentation() {\n return lib.indentation(this.text);\n }\n\n /**\n * Check if the string is empty or contains only whitespace\n * @returns True if empty or whitespace-only, false otherwise\n * @example\n * ```typescript\n * str('').isEmpty() // true\n * str(' \\n').isEmpty() // true\n * str('Hello').isEmpty() // false\n * ```\n */\n public isEmpty() {\n return lib.isEmpty(this.text);\n }\n\n /**\n * Replace the first occurrence of a substring or pattern\n * @param searchValue - The string or pattern to search for\n * @param replaceValue - The string to replace the match with\n * @returns A new Str instance with the first match replaced\n * @example\n * ```typescript\n * str('Hello World').replace('o', '0').$ // 'Hell0 World'\n * str('abc abc').replace(/[a-z]/, 'X').$ // 'Xbc abc'\n * ```\n */\n public replace(searchValue: string | RegExp, replaceValue: string) {\n return new Str(lib.replace(this.text, searchValue, replaceValue));\n }\n\n /**\n * Replace all occurrences of a substring or pattern\n * @param searchValue - The string or pattern to search for\n * @param replaceValue - The string to replace the matches with\n * @returns A new Str instance with all matches replaced\n * @example\n * ```typescript\n * str('Hello World').replaceAll('o', '0').$ // 'Hell0 W0rld'\n * str('abc abc').replaceAll(/[a-z]/g, 'X').$ // 'XXX XXX'\n * ```\n */\n public replaceAll(searchValue: string | RegExp, replaceValue: string) {\n return new Str(lib.replaceAll(this.text, searchValue, replaceValue));\n }\n\n /**\n * Convert string to camelCase\n * @returns A new Str instance in camelCase\n * @example\n * ```typescript\n * str('hello-world').camelCase().$ // 'helloWorld'\n * ```\n */\n public camelCase() {\n return new Str(changeCase.camelCase(this.text));\n }\n\n /**\n * Convert string to Capital Case\n * @returns A new Str instance in Capital Case\n * @example\n * ```typescript\n * str('hello-world').capitalCase().$ // 'Hello World'\n * ```\n */\n public capitalCase() {\n return new Str(changeCase.capitalCase(this.text));\n }\n\n /**\n * Convert string to CONSTANT_CASE\n * @returns A new Str instance in CONSTANT_CASE\n * @example\n * ```typescript\n * str('hello-world').constantCase().$ // 'HELLO_WORLD'\n * ```\n */\n public constantCase() {\n return new Str(changeCase.constantCase(this.text));\n }\n\n /**\n * Convert string to dot.case\n * @returns A new Str instance in dot.case\n * @example\n * ```typescript\n * str('hello-world').dotCase().$ // 'hello.world'\n * ```\n */\n public dotCase() {\n return new Str(changeCase.dotCase(this.text));\n }\n\n /**\n * Convert string to kebab-case\n * @returns A new Str instance in kebab-case\n * @example\n * ```typescript\n * str('helloWorld').kebabCase().$ // 'hello-world'\n * ```\n */\n public kebabCase() {\n return new Str(changeCase.kebabCase(this.text));\n }\n\n /**\n * Convert string to no case\n * @returns A new Str instance with no case\n * @example\n * ```typescript\n * str('helloWorld').noCase().$ // 'hello world'\n * ```\n */\n public noCase() {\n return new Str(changeCase.noCase(this.text));\n }\n\n /**\n * Convert string to PascalCase\n * @returns A new Str instance in PascalCase\n * @example\n * ```typescript\n * str('hello-world').pascalCase().$ // 'HelloWorld'\n * ```\n */\n public pascalCase() {\n return new Str(changeCase.pascalCase(this.text));\n }\n\n /**\n * Convert string to Pascal_Snake_Case\n * @returns A new Str instance in Pascal_Snake_Case\n * @example\n * ```typescript\n * str('hello-world').pascalSnakeCase().$ // 'Hello_World'\n * ```\n */\n public pascalSnakeCase() {\n return new Str(changeCase.pascalSnakeCase(this.text));\n }\n\n /**\n * Convert string to path/case\n * @returns A new Str instance in path/case\n * @example\n * ```typescript\n * str('hello-world').pathCase().$ // 'hello/world'\n * ```\n */\n public pathCase() {\n return new Str(changeCase.pathCase(this.text));\n }\n\n /**\n * Convert string to Sentence case\n * @returns A new Str instance in Sentence case\n * @example\n * ```typescript\n * str('hello-world').sentenceCase().$ // 'Hello world'\n * ```\n */\n public sentenceCase() {\n return new Str(changeCase.sentenceCase(this.text));\n }\n\n /**\n * Convert string to snake_case\n * @returns A new Str instance in snake_case\n * @example\n * ```typescript\n * str('helloWorld').snakeCase().$ // 'hello_world'\n * ```\n */\n public snakeCase() {\n return new Str(changeCase.snakeCase(this.text));\n }\n\n /**\n * Convert string to Train-Case\n * @returns A new Str instance in Train-Case\n * @example\n * ```typescript\n * str('hello-world').trainCase().$ // 'Hello-World'\n * ```\n */\n public trainCase() {\n return new Str(changeCase.trainCase(this.text));\n }\n\n /**\n * Get the underlying string value\n * @returns The wrapped string value\n * @example\n * ```typescript\n * str('hello').str // 'hello'\n * ```\n */\n public get str() {\n return this.toString();\n }\n}\n\n/**\n * Create a new Str instance from any stringable value\n * @param text - Any value that can be converted to a string\n * @returns A new Str instance wrapping the string value\n * @example\n * ```typescript\n * str('hello') // from string\n * str(123) // from number\n * str({ toString() }) // from object with toString\n * ```\n */\nexport const str = (text: Stringable) => {\n return new Str(text.toString());\n};\n","/**\n * Remove empty lines at the start of the text but leave whitespace on the first line with content\n * @param text - The input string to process\n * @returns The string with empty lines removed from the start\n * @example\n * ```typescript\n * chopEmptyLinesStart(\"\\n\\n \\n Hello\") // \" Hello\"\n * chopEmptyLinesStart(\" Hello\") // \" Hello\"\n * ```\n */\nexport const chopEmptyLinesStart = (text: string) => {\n return text.replace(/^(\\s*\\n)+/, \"\");\n};\n\n/**\n * Remove empty lines at the end of the text but leave whitespace on the last line with content\n * @param text - The input string to process\n * @returns The string with empty lines removed from the end\n * @example\n * ```typescript\n * chopEmptyLinesEnd(\"Hello\\n\\n \\n\") // \"Hello\"\n * chopEmptyLinesEnd(\"Hello \") // \"Hello \"\n * ```\n */\nexport const chopEmptyLinesEnd = (text: string) => {\n return text.replace(/(\\n\\s*)+$/, \"\");\n};\n\n/**\n * Remove all space characters in lines that contain no content\n * @param text - The input string to process\n * @returns The string with whitespace removed from empty lines\n * @example\n * ```typescript\n * trimEmptyLines(\"Hello\\n \\nWorld\") // \"Hello\\n\\nWorld\"\n * trimEmptyLines(\" \\n \\n \") // \"\\n\\n\"\n * ```\n */\nexport const trimEmptyLines = (text: string) => {\n return text.replace(/(^|\\n)\\s+(\\n|$)/g, \"$1$2\");\n};\n\n/**\n * Remove all space characters at the end of each line\n * @param text - The input string to process\n * @returns The string with trailing spaces removed from all lines\n * @example\n * ```typescript\n * trimLinesTrailingSpaces(\"Hello \\nWorld \") // \"Hello\\nWorld\"\n * trimLinesTrailingSpaces(\"Hello \") // \"Hello\"\n * ```\n */\nexport const trimLinesTrailingSpaces = (text: string) => {\n return text.replace(/ +(\\n|$)/g, \"$1\");\n};\n\n/**\n * Remove leading and trailing whitespace and line terminator characters\n * @param text - The input string to process\n * @returns The trimmed string\n * @example\n * ```typescript\n * trim(\" Hello World \") // \"Hello World\"\n * trim(\"\\n Hello \\n\") // \"Hello\"\n * ```\n */\nexport const trim = (text: string) => {\n return text.trim();\n};\n\n/**\n * Remove leading whitespace and line terminator characters\n * @param text - The input string to process\n * @returns The string with leading whitespace removed\n * @example\n * ```typescript\n * trimStart(\" Hello World \") // \"Hello World \"\n * trimStart(\"\\n Hello\") // \"Hello\"\n * ```\n */\nexport const trimStart = (text: string) => {\n return text.trimStart();\n};\n\n/**\n * Remove trailing whitespace and line terminator characters\n * @param text - The input string to process\n * @returns The string with trailing whitespace removed\n * @example\n * ```typescript\n * trimEnd(\" Hello World \") // \" Hello World\"\n * trimEnd(\"Hello \\n\") // \"Hello\"\n * ```\n */\nexport const trimEnd = (text: string) => {\n return text.trimEnd();\n};\n\n/**\n * Split a string into substrings using the specified separator\n * @param text - The input string to split\n * @param separator - The string or regular expression to use for splitting\n * @param limit - Optional limit on the number of splits to perform\n * @returns An array of substrings\n * @example\n * ```typescript\n * split(\"Hello World\", \" \") // [\"Hello\", \"World\"]\n * split(\"a,b,c\", \",\", 2) // [\"a\", \"b\"]\n * split(\"a.b-c\", /[.-]/) // [\"a\", \"b\", \"c\"]\n * ```\n */\nexport const split = (\n text: string,\n separator: string | RegExp,\n limit?: number,\n) => {\n return text.split(separator, limit);\n};\n\n/**\n * Add line numbers to each line in a string\n * @param text - The string to add line numbers to\n * @param separator - The separator between line number and content (defaults to \":\")\n * @returns The string with line numbers added\n * @example\n * ```typescript\n * addLineNumbers(\"Hello\\nWorld\") // \"0:Hello\\n1:World\"\n * addLineNumbers(\"A\\nB\\nC\", \" -> \") // \"0 -> A\\n1 -> B\\n2 -> C\"\n * ```\n */\nexport const addLineNumbers = (text: string, separator: string = \":\") => {\n return text\n .split(\"\\n\")\n .map((line, index) => `${index}${separator}${line}`)\n .join(\"\\n\");\n};\n\n/**\n * Calculate the minimum indentation level of non-empty lines in the string\n * @param text - The input string to analyze\n * @returns The number of spaces in the minimum indentation level, or 0 if no indentation found\n * @example\n * ```typescript\n * indentation(\" Hello\\n World\") // 2\n * indentation(\"Hello\\n World\") // 0\n * indentation(\" \\n Hello\") // 4\n * ```\n */\nexport const indentation = (text: string) => {\n return (\n text.split(\"\\n\").reduce((acc: number | null, line) => {\n if (line.trim() === \"\") return acc;\n const indentation = leadingSpacesCount(line);\n if (acc === null) return indentation;\n return Math.min(acc, indentation);\n }, null) ?? 0\n );\n};\n\n/**\n * Indent each line of the string by a specified number of spaces\n * @param text - The input string to indent\n * @param size - The number of spaces to add at the start of each line\n * @param char - The character to use for indentation (defaults to space)\n * @returns The indented string\n * @example\n * ```typescript\n * indent(\"Hello\\nWorld\", 2) // \" Hello\\n World\"\n * indent(\"A\\nB\", 3, \"-\") // \"---A\\n---B\"\n * ```\n */\nexport const indent = (text: string, size: number, char: string = \" \") => {\n if (size === 0) return text;\n\n const indentStr = char.repeat(size);\n return text\n .split(\"\\n\")\n .map((line) => indentStr + line)\n .join(\"\\n\");\n};\n\n/**\n * Remove indentation from each line of the string\n * @param text - The input string to dedent\n * @param size - Optional number of spaces to remove. If not provided, removes the minimum common indentation\n * @returns The dedented string\n * @example\n * ```typescript\n * dedent(\" Hello\\n World\") // \"Hello\\n World\"\n * dedent(\" A\\n B\", 2) // \" A\\nB\"\n * ```\n */\nexport const dedent = (text: string, size?: number) => {\n const _size = size ?? indentation(text);\n if (_size === 0) return text;\n const regex = new RegExp(`^\\\\s{1,${_size}}`);\n return text\n .split(\"\\n\")\n .map((line) => line.replace(regex, \"\"))\n .join(\"\\n\");\n};\n\n/**\n * Remove a specified number of characters from the end of the string\n * @param text - The input string to process\n * @param count - The number of characters to remove\n * @returns The string with characters removed from the end\n * @example\n * ```typescript\n * chopEnd(\"Hello World\", 6) // \"Hello\"\n * chopEnd(\"Hello\", 0) // \"Hello\"\n * ```\n */\nexport const chopEnd = (text: string, count: number) => {\n if (count === 0) return text;\n return text.slice(0, -count);\n};\n\n/**\n * Remove a specified number of characters from the start of the string\n * @param text - The input string to process\n * @param count - The number of characters to remove\n * @returns The string with characters removed from the start\n * @example\n * ```typescript\n * chopStart(\"Hello World\", 6) // \"World\"\n * chopStart(\"Hello\", 0) // \"Hello\"\n * ```\n */\nexport const chopStart = (text: string, count: number) => {\n if (count === 0) return text;\n return text.slice(count);\n};\n\n/**\n * Limit the number of consecutive newlines in the string\n * @param text - The input string to process\n * @param maxRepeat - The maximum number of consecutive newlines to allow\n * @returns The string with consecutive newlines limited\n * @example\n * ```typescript\n * chopRepeatNewlines(\"A\\n\\n\\n\\nB\", 2) // \"A\\n\\nB\"\n * chopRepeatNewlines(\"A\\n\\nB\", 1) // \"A\\nB\"\n * ```\n */\nexport const chopRepeatNewlines = (text: string, maxRepeat: number) => {\n if (maxRepeat === 0) return text;\n return text.replace(\n new RegExp(`\\n{${maxRepeat + 1},}`, \"g\"),\n \"\\n\".repeat(maxRepeat),\n );\n};\n\n/**\n * Extract a specified number of characters from the start of the string\n * @param text - The input string to process\n * @param count - The number of characters to take\n * @returns The extracted substring from the start\n * @example\n * ```typescript\n * takeStart(\"Hello World\", 5) // \"Hello\"\n * takeStart(\"Hi\", 5) // \"Hi\"\n * ```\n */\nexport const takeStart = (text: string, count: number) => {\n return text.slice(0, count);\n};\n\n/**\n * Extract a specified number of characters from the end of the string\n * @param text - The input string to process\n * @param count - The number of characters to take\n * @returns The extracted substring from the end\n * @example\n * ```typescript\n * takeEnd(\"Hello World\", 5) // \"World\"\n * takeEnd(\"Hi\", 5) // \"Hi\"\n * ```\n */\nexport const takeEnd = (text: string, count: number) => {\n return text.slice(-count);\n};\n\n/**\n * Get the last line of a multi-line string\n * @param text - The input string to process\n * @returns The last line of the string, or empty string if input is empty\n * @example\n * ```typescript\n * lastLine(\"Hello\\nWorld\") // \"World\"\n * lastLine(\"Hello\") // \"Hello\"\n * lastLine(\"\") // \"\"\n * ```\n */\nexport const lastLine = (text: string) => {\n return text.split(\"\\n\").at(-1) ?? \"\";\n};\n\n/**\n * Get the first line of a multi-line string\n * @param text - The input string to process\n * @returns The first line of the string, or empty string if input is empty\n * @example\n * ```typescript\n * firstLine(\"Hello\\nWorld\") // \"Hello\"\n * firstLine(\"Hello\") // \"Hello\"\n * firstLine(\"\") // \"\"\n * ```\n */\nexport const firstLine = (text: string) => {\n return text.split(\"\\n\").at(0) ?? \"\";\n};\n\n/**\n * Count the number of leading space characters in a string\n * @param text - The input string to analyze\n * @returns The number of leading space characters\n * @example\n * ```typescript\n * leadingSpacesCount(\" Hello\") // 2\n * leadingSpacesCount(\"Hello\") // 0\n * ```\n */\nexport const leadingSpacesCount = (text: string) => {\n return text.match(/^\\s+/)?.at(0)?.length ?? 0;\n};\n\n/**\n * Check if a string is empty or contains only whitespace\n * @param text - The input string to check\n * @returns True if the string is empty or contains only whitespace, false otherwise\n * @example\n * ```typescript\n * isEmpty(\"\") // true\n * isEmpty(\" \\n \") // true\n * isEmpty(\"Hello\") // false\n * ```\n */\nexport const isEmpty = (text: string) => {\n return text.trim() === \"\";\n};\n\n/**\n * Replace the first occurrence of a substring or pattern in the string\n * @param text - The input string to process\n * @param searchValue - The string or pattern to search for\n * @param replaceValue - The string to replace the match with\n * @returns The string with the first match replaced\n * @example\n * ```typescript\n * replace(\"Hello World\", \"o\", \"0\") // \"Hell0 World\"\n * replace(\"abc abc\", /[a-z]/, \"X\") // \"Xbc abc\"\n * ```\n */\nexport const replace = (\n text: string,\n searchValue: string | RegExp,\n replaceValue: string,\n) => {\n return text.replace(searchValue, replaceValue);\n};\n\n/**\n * Replace all occurrences of a substring or pattern in the string\n * @param text - The input string to process\n * @param searchValue - The string or pattern to search for\n * @param replaceValue - The string to replace the matches with\n * @returns The string with all matches replaced\n * @example\n * ```typescript\n * replaceAll(\"Hello World\", \"o\", \"0\") // \"Hell0 W0rld\"\n * replaceAll(\"abc abc\", /[a-z]/g, \"X\") // \"XXX XXX\"\n * ```\n */\nexport const replaceAll = (\n text: string,\n searchValue: string | RegExp,\n replaceValue: string,\n) => {\n if (typeof searchValue === \"string\") {\n return text.replaceAll(searchValue, replaceValue);\n }\n // Ensure the RegExp has the global flag\n const flags = searchValue.flags.includes(\"g\")\n ? searchValue.flags\n : searchValue.flags + \"g\";\n const globalRegex = new RegExp(searchValue.source, flags);\n return text.replace(globalRegex, replaceValue);\n};\n"],"mappings":";AAAA;AAAA,EACE,aAAAA;AAAA,EACA,eAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,aAAAC;AAAA,EACA,aAAAC;AAAA,OACK;;;ACbP,SAAS,gBAA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","pathCase","sentenceCase","snakeCase","trainCase","indentation","indentation"]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "1.1.3",
7
+ "version": "1.2.0",
8
8
  "description": "Advanced chainable string manipulation",
9
9
  "keywords": [
10
10
  "string",
@@ -28,8 +28,8 @@
28
28
  "build": "tsup",
29
29
  "build:watch": "tsup --watch",
30
30
  "test:types": "tsc --noEmit",
31
- "test:unit": "node --experimental-strip-types --test src/**/*.test.ts",
32
- "test:unit:watch": "node --experimental-strip-types --watch --test --watch src/**/*.test.ts",
31
+ "test:unit": "node --experimental-strip-types --experimental-test-snapshots --no-warnings --test src/**/*.test.ts",
32
+ "test:unit:watch": "node --experimental-strip-types --experimental-test-snapshots --no-warnings --watch --test --watch src/**/*.test.ts",
33
33
  "test": "yarn test:types && yarn test:unit",
34
34
  "prepare": "yarn test && yarn build"
35
35
  },
@@ -59,5 +59,5 @@
59
59
  "!src/**/*.test.ts",
60
60
  "dist/**/*"
61
61
  ],
62
- "gitHead": "34bad542796c3d22efe0b4f7f4aabb05ec72aebd"
62
+ "gitHead": "bd0573bc2521371c355953766911b6523a3a4709"
63
63
  }