{"_id":"@caelus-utils/strfmt","name":"@caelus-utils/strfmt","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@caelus-utils/strfmt","version":"0.1.0","description":"A lightweight utility library providing a comprehensive set of string formatting and manipulation functions for JavaScript/TypeScript projects.","publishConfig":{"registry":"https://registry.npmjs.org/"},"main":"dist/cjs/index.js","module":"dist/es/index.js","types":"dist/types/index.d.ts","scripts":{"build":"vite build","test":"jest --detectOpenHandles"},"keywords":[],"author":{"name":"Caelus"},"license":"MIT","exports":{".":{"types":"./dist/types/index.d.ts","require":"./dist/cjs/index.js","import":"./dist/es/index.js","default":"./dist/es/index.js"}},"devDependencies":{"@types/jest":"^29.5.14","jest":"^29.7.0","node-notifier":"^10.0.1","ts-jest":"^29.2.5","vite":"^6.0.5","vite-plugin-dts":"^4.4.0"},"repository":{"url":"git+https://github.com/caelus-lab/caelus-utils-strfmt.git"},"bugs":{"url":"https://github.com/caelus-lab/caelus-utils-strfmt/issues"},"homepage":"https://github.com/caelus-lab/caelus-utils-strfmt#readme","_id":"@caelus-utils/strfmt@0.1.0","gitHead":"c62b7ef95d884b7a9d06893c998f2079c3a360c3","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-KehoG7sKjTqFkFVIC8hapL4XLwhev+QjQNMk6giLZlgucTB9Ht2gtInC1AXPdH56FfsPZrNdXysWOkoYDeRxTw==","shasum":"7fe549e9da142237a618d1e0ce72c739facd71e3","tarball":"https://registry.npmjs.org/@caelus-utils/strfmt/-/strfmt-0.1.0.tgz","fileCount":6,"unpackedSize":24770,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC+CaCAniMXnLmfEb8fg33JOU0G82BcrHnsuumbqcxcbwIgWB1DPMERA91u1XfpP3WVtOGkIOokvmyrb15dx+w29TQ="}]},"_npmUser":{"name":"caelus-lib","email":"caelus.team@hotmail.com"},"directories":{},"maintainers":[{"name":"caelus-lib","email":"caelus.team@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/strfmt_0.1.0_1736436711158_0.4005770122333754"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-09T15:31:51.030Z","0.1.0":"2025-01-09T15:31:51.332Z","modified":"2025-01-09T15:31:51.576Z"},"maintainers":[{"name":"caelus-lib","email":"caelus.team@hotmail.com"}],"description":"A lightweight utility library providing a comprehensive set of string formatting and manipulation functions for JavaScript/TypeScript projects.","homepage":"https://github.com/caelus-lab/caelus-utils-strfmt#readme","keywords":[],"repository":{"url":"git+https://github.com/caelus-lab/caelus-utils-strfmt.git"},"author":{"name":"Caelus"},"bugs":{"url":"https://github.com/caelus-lab/caelus-utils-strfmt/issues"},"license":"MIT","readme":"# String formatting @caelus-utils/strfmt\r\n\r\nA lightweight utility library providing a comprehensive set of string formatting and manipulation functions for JavaScript/TypeScript projects.  This package simplifies common string operations such as case conversion, splitting, replacing, padding, and more.  It aims to be a one-stop solution for your string manipulation needs, making your code cleaner and more efficient.\r\n\r\n## Installation\r\n- using `npm`\r\n```shell\r\nnpm install @caelus-utils/strfmt\r\n```\r\n- using `yarn`\r\n```shell\r\nyarn add @caelus-utils/strfmt\r\n```\r\n- using `pnpm`\r\n```shell\r\npnpm add @caelus-utils/strfmt\r\n```\r\n\r\n## Functions\r\n\r\n### `isEmptyStr(str, config)`\r\n\r\nChecks if a given string is empty.\r\n\r\n*   **`str`**: The string to check.\r\n*   **`config`**: An optional configuration object.\r\n    *   **`ignoreWhitespace`**: Determines whether whitespace characters should be ignored during processing. Defaults to `true`.\r\n\r\nReturns `true` if the string is considered empty, `false` otherwise.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {isEmptyStr} from \"@caelus-utils/strfmt\";\r\n\r\nisEmptyStr(''); // true\r\nisEmptyStr('  '); // true\r\nisEmptyStr('  ', {ignoreWhitespace: false}); // false\r\nisEmptyStr(' hello '); // false\r\n```\r\n\r\n\r\n### `splitStr(sentence, onlyLetterNumber)`\r\n\r\nSplits a given sentence into an array of words based on various delimiters and patterns.\r\n\r\n*   **`sentence`**: The input string to be split into words.\r\n*   **`onlyLetterNumber`**: If `true`, filters the resulting array to include only words containing alphanumeric characters (letters and numbers only). Defaults to `false`.\r\n\r\nReturns an array of words (string) obtained by splitting the input sentence.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {splitStr} from \"@caelus-utils/strfmt\";\r\n\r\nsplitStr('hello world'); // ['hello', 'world']\r\n```\r\n\r\n\r\n### `strReplace(string, payload)`\r\n\r\nReplaces occurrences of a search string or multiple search strings in the given input string with the specified replacement value(s).\r\n\r\n*   **`string`**: The input string to perform replacements on.\r\n*   **`payload`**: The replacement payload(s). It can be a single payload object or an array of payload objects. Each payload includes the `search` string to be replaced and the `replace` value.\r\n    *   **`search`**:  A string or regular expression (string | RegExp) to specify the search pattern.\r\n    *   **`replace`**: A string or a function to replace parts of a string.\r\n\r\nReturns the resulting string after all replacements have been applied.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {strReplace} from \"@caelus-utils/strfmt\";\r\n\r\nstrReplace('hello world', {search: 'world', replace: 'everyone'}); // 'hello everyone'\r\nstrReplace('hello world', [{search: 'hello', replace: 'hi'}, {search: 'world', replace: 'everyone!'}]); // 'hi everyone!'\r\n```\r\n\r\n\r\n### `capitalize(str)`\r\n\r\nCapitalizes the first letter of a given string.\r\n\r\n*   **`str`**: The input string to be capitalized.\r\n\r\nReturns the modified string with the first letter capitalized.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {capitalize} from \"@caelus-utils/strfmt\";\r\n\r\ncapitalize('hello world'); // Hello world\r\n```\r\n\r\n\r\n### `uncapitalize(str)`\r\n\r\nConverts the first character of a string to lowercase and returns the modified string.\r\n\r\n*   **`str`**: The input string to process.\r\n\r\nReturns the input string with the first character converted to lowercase.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {uncapitalize} from \"@caelus-utils/strfmt\";\r\n\r\nuncapitalize('Hello World'); // hello World\r\n```\r\n\r\n\r\n### `titleCase(str)`\r\n\r\nConverts a given string into title case format, where the first letter of each word is capitalized.\r\n\r\n*   **`str`**: The input string to be transformed into title case.\r\n\r\nReturns the transformed string in title case.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {titleCase} from \"@caelus-utils/strfmt\";\r\n\r\ntitleCase('hello world'); // Hello World\r\n```\r\n\r\n\r\n### `camelCase(str)`\r\n\r\nConverts a given string to camelCase format.\r\n\r\n*   **`str`**: The input string to be transformed into camelCase.\r\n\r\nReturns the camelCase formatted string.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {camelCase} from \"@caelus-utils/strfmt\";\r\n\r\ncamelCase('hello world'); // helloWorld\r\n```\r\n\r\n\r\n### `constantCase(str)`\r\n\r\nConverts a given string to constant case, where all letters are uppercase and words are separated by underscores.\r\n\r\n*   **`str`**: The input string to be converted.\r\n\r\nReturns the string converted to constant case.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {constantCase} from \"@caelus-utils/strfmt\";\r\n\r\nconstantCase('hello world'); // HELLO_WORLD\r\n```\r\n\r\n\r\n### `snakeCase(str)`\r\n\r\nConverts a given string into snake_case format.\r\n\r\n*   **`str`**: The input string to be converted.\r\n\r\nReturns the transformed string in snake_case format.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {snakeCase} from \"@caelus-utils/strfmt\";\r\n\r\nsnakeCase('hello world'); // hello_world\r\n```\r\n\r\n\r\n### `kebabCase(str)`\r\n\r\nConverts a given string to kebab-case by transforming it to lowercase and separating words with dashes.\r\n\r\n*   **`str`**: The input string to be transformed into kebab-case.\r\n\r\nReturns the transformed string in kebab-case format.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {kebabCase} from \"@caelus-utils/strfmt\";\r\n\r\nkebabCase('hello world'); // hello-world\r\n```\r\n\r\n\r\n### `pascalCase(str)`\r\n\r\nConverts a given string to PascalCase.\r\n\r\n*   **`str`**: The input string to be transformed into PascalCase.\r\n\r\nReturns the string converted to PascalCase.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {pascalCase} from \"@caelus-utils/strfmt\";\r\n\r\npascalCase('hello world'); // HelloWorld\r\n```\r\n\r\n\r\n### `strRmSpace(str)`\r\n\r\nRemoves all whitespace characters from the given string.\r\n\r\n*   **`str`**: The input string from which spaces will be removed.\r\n\r\nReturns the resulting string with all spaces removed.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {strRmSpace} from \"@caelus-utils/strfmt\";\r\n\r\nstrRmSpace(' hello world '); // helloworld\r\n```\r\n\r\n\r\n### `padStr(str, config)`\r\n\r\nPads the given string or number with a specified prefix to a desired length.\r\n\r\n*   **`str`**: The string or number to be padded.\r\n*   **`config`**: The configuration object for padding.\r\n    *   **`size`**: The desired length of the final padded string. Defaults to 2.\r\n    *   **`position`**: The position where the padding should be added, either 'start' or 'end'. Defaults to `start`.\r\n    *   **`prefix`**: The string to be used as the padding character(s). Defaults to an empty string.\r\n\r\n**Note: if no `prefix` was provided nothing occur to the `str` value**\r\n\r\nReturns the padded string based on the configuration provided.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {padStr} from \"@caelus-utils/strfmt\";\r\n\r\npadStr('1', {size: 3, prefix: '0'}); // '001'\r\npadStr(1, {size: 3, prefix: 0}); // '001'\r\n```\r\n\r\n\r\n### `charCode(input, hexCase)`\r\n\r\nConverts the characters in the input string to their hexadecimal Unicode representation.\r\n\r\n*   **`input`**: The input string to be converted to hexadecimal representation.\r\n*   **`hexCase`**: If `true`, the output hexadecimal values will be in uppercase; otherwise, they will be in lowercase. Defaults to `false`.\r\n\r\nReturns the string containing the hexadecimal representation of the input characters.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {charCode} from \"@caelus-utils/strfmt\";\r\n\r\ncharCode('A'); // '41'\r\n```\r\n\r\n\r\n### `strConcat(payload, sharedDivider)`\r\n\r\nConcatenates an iterable of strings, numbers, or booleans with a specified divider.\r\n\r\n*   **`payload`**: Can be a single `StrConcatPayload` object or an array of them. Contains `values` and `divider`\r\n    *   **`values`**: An iterable of strings, numbers or booleans to be concatenated.\r\n    *   **`divider`**: An optional string used to divide between the concatenated values. Defaults to an empty string.\r\n\r\n*   **`sharedDivider`**: An optional string used as a divider between concatenated values for all payloads in case `payload` is an array.\r\n\r\nReturns the concatenated string with the specified divider between elements or an array of strings when the input is an array of payloads.\r\n\r\n**Usage Example**\r\n\r\n```typescript\r\nimport {strConcat} from \"@caelus-utils/strfmt\";\r\n\r\nstrConcat({values: ['hello', 'world'], divider: '-'}); // 'hello-world'\r\n// Each value has it's own divider\r\nstrConcat([{values: ['hello', 'world'], divider: '-'}, {values: ['hi', 'everyone!'], divider: '-'}]); // ['hello-world', 'hi-everyone!']\r\n// All the values will share the same divider\r\nstrConcat([{values: ['hello', 'world']}, {values: ['hi', 'everyone!']}], '-'); // ['hello-world', 'hi-everyone!']\r\n```\r\n\r\n\r\n## Contributing\r\nContributions are welcome! Please fork the repository and submit a pull request.\r\n\r\n## License\r\n[MIT License](LICENSE)","readmeFilename":"README.md"}