@stryke/string-format 0.3.0 → 0.4.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.
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.camelCase = void 0;
6
+ exports.camelCase = camelCase;
7
7
  var _lowerCaseFirst = require("./lower-case-first.cjs");
8
8
  var _pascalCase = require("./pascal-case.cjs");
9
- const camelCase = r => r && (0, _lowerCaseFirst.lowerCaseFirst)((0, _pascalCase.pascalCase)(r));
10
- exports.camelCase = camelCase;
9
+ function camelCase(e) {
10
+ return e && (0, _lowerCaseFirst.lowerCaseFirst)((0, _pascalCase.pascalCase)(e));
11
+ }
@@ -7,4 +7,4 @@
7
7
  * @param input - The input string.
8
8
  * @returns The camel-cased string.
9
9
  */
10
- export declare const camelCase: (input?: string) => string | undefined;
10
+ export declare function camelCase<T extends string | undefined>(input: T): T;
@@ -1 +1 @@
1
- import{lowerCaseFirst as e}from"./lower-case-first";import{pascalCase as s}from"./pascal-case";export const camelCase=r=>r&&e(s(r));
1
+ import{lowerCaseFirst as r}from"./lower-case-first";import{pascalCase as o}from"./pascal-case";export function camelCase(e){return e&&r(o(e))}
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.constantCase = void 0;
6
+ exports.constantCase = constantCase;
7
7
  var _snakeCase = require("./snake-case.cjs");
8
- const constantCase = e => (0, _snakeCase.snakeCase)(e)?.toUpperCase();
9
- exports.constantCase = constantCase;
8
+ function constantCase(e) {
9
+ return (0, _snakeCase.snakeCase)(e)?.toUpperCase();
10
+ }
@@ -7,4 +7,4 @@
7
7
  * @param input - The input string.
8
8
  * @returns The constant-cased string.
9
9
  */
10
- export declare const constantCase: (input?: string) => string | undefined;
10
+ export declare function constantCase<T extends string | undefined>(input: T): T;
@@ -1 +1 @@
1
- import{snakeCase as n}from"./snake-case";export const constantCase=e=>n(e)?.toUpperCase();
1
+ import{snakeCase as n}from"./snake-case";export function constantCase(e){return n(e)?.toUpperCase()}
@@ -7,6 +7,6 @@ exports.kebabCase = kebabCase;
7
7
  var _types = require("@stryke/types");
8
8
  var _upperCaseFirst = require("./upper-case-first.cjs");
9
9
  function kebabCase(t) {
10
- const e = t?.replace(/[A-Z]+/g, r => (0, _upperCaseFirst.upperCaseFirst)(r) ?? _types.EMPTY_STRING)?.split(/(?=[A-Z])|[\s._-]/).map(r => r.toLowerCase()) ?? [];
11
- return e.length === 0 ? "" : e.length === 1 ? e[0] : e.reduce((r, n) => `${r}-${n.toLowerCase()}`.toLowerCase());
10
+ const r = t?.replace(/[A-Z]+/g, e => (0, _upperCaseFirst.upperCaseFirst)(e) ?? _types.EMPTY_STRING)?.split(/(?=[A-Z])|[\s._-]/).map(e => e.toLowerCase()) ?? [];
11
+ return r.length === 0 ? "" : r.length === 1 ? r[0] : r.reduce((e, s) => `${e}-${s.toLowerCase()}`.toLowerCase());
12
12
  }
@@ -7,4 +7,4 @@
7
7
  * @param input - The input string.
8
8
  * @returns The kebab-cased string.
9
9
  */
10
- export declare function kebabCase(input?: string): string | undefined;
10
+ export declare function kebabCase<T extends string | undefined>(input: T): T;
@@ -1 +1 @@
1
- import{EMPTY_STRING as s}from"@stryke/types";import{upperCaseFirst as i}from"./upper-case-first";export function kebabCase(t){const e=t?.replace(/[A-Z]+/g,r=>i(r)??s)?.split(/(?=[A-Z])|[\s._-]/).map(r=>r.toLowerCase())??[];return e.length===0?"":e.length===1?e[0]:e.reduce((r,n)=>`${r}-${n.toLowerCase()}`.toLowerCase())}
1
+ import{EMPTY_STRING as n}from"@stryke/types";import{upperCaseFirst as o}from"./upper-case-first";export function kebabCase(t){const r=t?.replace(/[A-Z]+/g,e=>o(e)??n)?.split(/(?=[A-Z])|[\s._-]/).map(e=>e.toLowerCase())??[];return r.length===0?"":r.length===1?r[0]:r.reduce((e,s)=>`${e}-${s.toLowerCase()}`.toLowerCase())}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.lowerCaseFirst = void 0;
7
- const lowerCaseFirst = e => e && e.charAt(0).toLowerCase() + e.slice(1);
8
- exports.lowerCaseFirst = lowerCaseFirst;
6
+ exports.lowerCaseFirst = lowerCaseFirst;
7
+ function lowerCaseFirst(e) {
8
+ return e && e.charAt(0).toLowerCase() + e.slice(1);
9
+ }
@@ -7,4 +7,4 @@
7
7
  * @param input - The input string.
8
8
  * @returns The lower-cased string.
9
9
  */
10
- export declare const lowerCaseFirst: (input?: string) => string | undefined;
10
+ export declare function lowerCaseFirst<T extends string | undefined>(input?: T): T;
@@ -1 +1 @@
1
- export const lowerCaseFirst=e=>e&&e.charAt(0).toLowerCase()+e.slice(1);
1
+ export function lowerCaseFirst(e){return e&&e.charAt(0).toLowerCase()+e.slice(1)}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.pascalCase = void 0;
7
- const pascalCase = e => e && e.split(" ").map(r => r.length > 0 ? r.trim().charAt(0).toUpperCase() + r.trim().slice(1) : "").join("");
8
- exports.pascalCase = pascalCase;
6
+ exports.pascalCase = pascalCase;
7
+ function pascalCase(e) {
8
+ return e && e.split(" ").map(t => t.length > 0 ? t.trim().charAt(0).toUpperCase() + t.trim().slice(1) : "").join("");
9
+ }
@@ -7,4 +7,4 @@
7
7
  * @param input - The input string.
8
8
  * @returns The pascal-cased string.
9
9
  */
10
- export declare const pascalCase: (input?: string) => string | undefined;
10
+ export declare function pascalCase<T extends string | undefined>(input?: T): T;
@@ -1 +1 @@
1
- export const pascalCase=e=>e&&e.split(" ").map(r=>r.length>0?r.trim().charAt(0).toUpperCase()+r.trim().slice(1):"").join("");
1
+ export function pascalCase(e){return e&&e.split(" ").map(t=>t.length>0?t.trim().charAt(0).toUpperCase()+t.trim().slice(1):"").join("")}
@@ -3,11 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.periodSplit = void 0;
6
+ exports.periodSplit = periodSplit;
7
7
  var _types = require("@stryke/types");
8
8
  var _upperCaseFirst = require("./upper-case-first.cjs");
9
- const periodSplit = e => {
10
- const t = e?.replace(/[A-Z]+/g, r => (0, _upperCaseFirst.upperCaseFirst)(r) ?? _types.EMPTY_STRING)?.split(/(?=[A-Z])|[\s._-]/).map(r => r.toLowerCase()) ?? [];
11
- return t.length === 0 ? "" : t.length === 1 ? t[0] : t.reduce((r, n) => `${r}.${n.toLowerCase()}`.toLowerCase());
12
- };
13
- exports.periodSplit = periodSplit;
9
+ function periodSplit(t) {
10
+ const e = t?.replace(/[A-Z]+/g, r => (0, _upperCaseFirst.upperCaseFirst)(r) ?? _types.EMPTY_STRING)?.split(/(?=[A-Z])|[\s._-]/).map(r => r.toLowerCase()) ?? [];
11
+ return e.length === 0 ? "" : e.length === 1 ? e[0] : e.reduce((r, s) => `${r}.${s.toLowerCase()}`.toLowerCase());
12
+ }
@@ -7,4 +7,4 @@
7
7
  * @param input - The input string.
8
8
  * @returns The period-split string.
9
9
  */
10
- export declare const periodSplit: (input?: string) => string | undefined;
10
+ export declare function periodSplit<T extends string | undefined>(input?: T): T;
@@ -1 +1 @@
1
- import{EMPTY_STRING as s}from"@stryke/types";import{upperCaseFirst as i}from"./upper-case-first";export const periodSplit=e=>{const t=e?.replace(/[A-Z]+/g,r=>i(r)??s)?.split(/(?=[A-Z])|[\s._-]/).map(r=>r.toLowerCase())??[];return t.length===0?"":t.length===1?t[0]:t.reduce((r,n)=>`${r}.${n.toLowerCase()}`.toLowerCase())};
1
+ import{EMPTY_STRING as n}from"@stryke/types";import{upperCaseFirst as i}from"./upper-case-first";export function periodSplit(t){const e=t?.replace(/[A-Z]+/g,r=>i(r)??n)?.split(/(?=[A-Z])|[\s._-]/).map(r=>r.toLowerCase())??[];return e.length===0?"":e.length===1?e[0]:e.reduce((r,s)=>`${r}.${s.toLowerCase()}`.toLowerCase())}
@@ -3,15 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.snakeCase = void 0;
6
+ exports.snakeCase = snakeCase;
7
7
  var _types = require("@stryke/types");
8
8
  var _upperCaseFirst = require("./upper-case-first.cjs");
9
- const snakeCase = (t, n) => {
10
- if (!t) return "";
9
+ function snakeCase(t, n) {
10
+ if (!t) return t;
11
11
  const r = t?.replace(/[A-Z]+/g, e => (0, _upperCaseFirst.upperCaseFirst)(e) ?? _types.EMPTY_STRING).split(/(?=[A-Z])|[\s._-]/).map(e => e.toLowerCase()) ?? [];
12
12
  if (r.length === 0) return "";
13
13
  if (r.length === 1) return r[0];
14
14
  const s = r.reduce((e, i) => `${e}_${i.toLowerCase()}`);
15
15
  return n?.splitOnNumber === !1 ? s : s.replace(/[A-Z]\d/i, e => `${e[0]}_${e[1]}`);
16
- };
17
- exports.snakeCase = snakeCase;
16
+ }
@@ -11,4 +11,4 @@ export interface SnakeCaseOptions {
11
11
  * @param options - Options to control the behavior of the function.
12
12
  * @returns The snake-cased string.
13
13
  */
14
- export declare const snakeCase: (input?: string, options?: SnakeCaseOptions) => string;
14
+ export declare function snakeCase<T extends string | undefined>(input: T, options?: SnakeCaseOptions): T;
@@ -1 +1 @@
1
- import{EMPTY_STRING as o}from"@stryke/types";import{upperCaseFirst as a}from"./upper-case-first";export const snakeCase=(t,n)=>{if(!t)return"";const r=t?.replace(/[A-Z]+/g,e=>a(e)??o).split(/(?=[A-Z])|[\s._-]/).map(e=>e.toLowerCase())??[];if(r.length===0)return"";if(r.length===1)return r[0];const s=r.reduce((e,i)=>`${e}_${i.toLowerCase()}`);return n?.splitOnNumber===!1?s:s.replace(/[A-Z]\d/i,e=>`${e[0]}_${e[1]}`)};
1
+ import{EMPTY_STRING as a}from"@stryke/types";import{upperCaseFirst as o}from"./upper-case-first";export function snakeCase(t,n){if(!t)return t;const r=t?.replace(/[A-Z]+/g,e=>o(e)??a).split(/(?=[A-Z])|[\s._-]/).map(e=>e.toLowerCase())??[];if(r.length===0)return"";if(r.length===1)return r[0];const s=r.reduce((e,i)=>`${e}_${i.toLowerCase()}`);return n?.splitOnNumber===!1?s:s.replace(/[A-Z]\d/i,e=>`${e[0]}_${e[1]}`)}
@@ -5,9 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.startCase = startCase;
7
7
  var _getWords = require("./get-words.cjs");
8
- function startCase(o) {
9
- const e = (0, _getWords.getWords)(o.trim());
10
- let t = "";
11
- for (const r of e) r && r[0] && (t && (t += " "), t += r === r.toUpperCase() ? r : r[0].toUpperCase() + r.slice(1).toLowerCase());
12
- return t;
8
+ function startCase(t) {
9
+ if (!t) return t;
10
+ const o = (0, _getWords.getWords)(t.trim());
11
+ let r = "";
12
+ for (const e of o) e && e[0] && (r && (r += " "), r += e === e.toUpperCase() ? e : e[0].toUpperCase() + e.slice(1).toLowerCase());
13
+ return r;
13
14
  }
@@ -14,7 +14,7 @@
14
14
  * const result4 = startCase('hello_world'); // result will be 'Hello World'
15
15
  * ```
16
16
  *
17
- * @param str - The string to convert.
17
+ * @param input - The string to convert.
18
18
  * @returns The converted string.
19
19
  */
20
- export declare function startCase(str: string): string;
20
+ export declare function startCase<T extends string | undefined>(input?: T): T;
@@ -1 +1 @@
1
- import{getWords as s}from"./get-words";export function startCase(o){const e=s(o.trim());let t="";for(const r of e)r&&r[0]&&(t&&(t+=" "),t+=r===r.toUpperCase()?r:r[0].toUpperCase()+r.slice(1).toLowerCase());return t}
1
+ import{getWords as s}from"./get-words";export function startCase(t){if(!t)return t;const o=s(t.trim());let r="";for(const e of o)e&&e[0]&&(r&&(r+=" "),r+=e===e.toUpperCase()?e:e[0].toUpperCase()+e.slice(1).toLowerCase());return r}
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.titleCase = void 0;
6
+ exports.titleCase = titleCase;
7
7
  var _acronyms = require("./acronyms.cjs");
8
8
  var _upperCaseFirst = require("./upper-case-first.cjs");
9
- const titleCase = e => e ? e.split(/(?=[A-Z])|[\s._-]/).map(r => r.trim()).filter(Boolean).map(r => _acronyms.ACRONYMS.includes(r) ? r.toUpperCase() : (0, _upperCaseFirst.upperCaseFirst)(r.toLowerCase())).join(" ") : "";
10
- exports.titleCase = titleCase;
9
+ function titleCase(r) {
10
+ return r && r.split(/(?=[A-Z])|[\s._-]/).map(e => e.trim()).filter(Boolean).map(e => _acronyms.ACRONYMS.includes(e) ? e.toUpperCase() : (0, _upperCaseFirst.upperCaseFirst)(e.toLowerCase())).join(" ");
11
+ }
@@ -7,4 +7,4 @@
7
7
  * @param input - The input string.
8
8
  * @returns The title cased string.
9
9
  */
10
- export declare const titleCase: (input?: string) => string | undefined;
10
+ export declare function titleCase<T extends string | undefined>(input?: T): T;
@@ -1 +1 @@
1
- import{ACRONYMS as t}from"./acronyms";import{upperCaseFirst as i}from"./upper-case-first";export const titleCase=e=>e?e.split(/(?=[A-Z])|[\s._-]/).map(r=>r.trim()).filter(Boolean).map(r=>t.includes(r)?r.toUpperCase():i(r.toLowerCase())).join(" "):"";
1
+ import{ACRONYMS as t}from"./acronyms";import{upperCaseFirst as o}from"./upper-case-first";export function titleCase(r){return r&&r.split(/(?=[A-Z])|[\s._-]/).map(e=>e.trim()).filter(Boolean).map(e=>t.includes(e)?e.toUpperCase():o(e.toLowerCase())).join(" ")}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.upperCaseFirst = void 0;
7
- const upperCaseFirst = e => e && e.charAt(0).toUpperCase() + e.slice(1);
8
- exports.upperCaseFirst = upperCaseFirst;
6
+ exports.upperCaseFirst = upperCaseFirst;
7
+ function upperCaseFirst(e) {
8
+ return e && e.charAt(0).toUpperCase() + e.slice(1);
9
+ }
@@ -7,4 +7,4 @@
7
7
  * @param input - The input string.
8
8
  * @returns The capitalized string.
9
9
  */
10
- export declare const upperCaseFirst: (input?: string) => string | undefined;
10
+ export declare function upperCaseFirst<T extends string | undefined>(input?: T): T;
@@ -1 +1 @@
1
- export const upperCaseFirst=e=>e&&e.charAt(0).toUpperCase()+e.slice(1);
1
+ export function upperCaseFirst(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/string-format",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "A package containing utility functions to transform strings into various formats.",
6
6
  "repository": {
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "private": false,
12
12
  "publishConfig": { "access": "public" },
13
- "dependencies": { "@stryke/helpers": ">=0.4.5", "@stryke/types": ">=0.7.3" },
13
+ "dependencies": { "@stryke/helpers": "^0.4.5", "@stryke/types": "^0.8.0" },
14
14
  "devDependencies": {},
15
15
  "sideEffects": false,
16
16
  "files": ["dist/**/*"],