@stryke/string-format 0.5.3 → 0.6.1
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.
- package/dist/camel-case.cjs +5 -1
- package/dist/camel-case.d.ts +11 -1
- package/dist/camel-case.mjs +1 -1
- package/dist/constant-case.cjs +6 -1
- package/dist/constant-case.d.ts +11 -1
- package/dist/constant-case.mjs +1 -1
- package/dist/get-words.cjs +1 -1
- package/dist/get-words.mjs +1 -1
- package/dist/kebab-case.cjs +5 -0
- package/dist/kebab-case.d.ts +11 -1
- package/dist/kebab-case.mjs +1 -1
- package/dist/pascal-case.cjs +7 -2
- package/dist/pascal-case.d.ts +11 -1
- package/dist/pascal-case.mjs +1 -1
- package/dist/snake-case.cjs +13 -7
- package/dist/snake-case.d.ts +11 -1
- package/dist/snake-case.mjs +1 -1
- package/dist/start-case.cjs +10 -6
- package/dist/start-case.d.ts +11 -3
- package/dist/start-case.mjs +1 -1
- package/dist/title-case.cjs +9 -5
- package/dist/title-case.d.ts +12 -2
- package/dist/title-case.mjs +1 -1
- package/package.json +3 -3
package/dist/camel-case.cjs
CHANGED
|
@@ -4,8 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.camelCase = camelCase;
|
|
7
|
+
exports.isCamelCase = isCamelCase;
|
|
7
8
|
var _lowerCaseFirst = require("./lower-case-first.cjs");
|
|
8
9
|
var _pascalCase = require("./pascal-case.cjs");
|
|
10
|
+
function isCamelCase(e) {
|
|
11
|
+
return e ? /^[a-z][a-zA-Z0-9]*$/.test(e) : !1;
|
|
12
|
+
}
|
|
9
13
|
function camelCase(e) {
|
|
10
|
-
return e
|
|
14
|
+
return isCamelCase(e) || e === void 0 ? e : (0, _lowerCaseFirst.lowerCaseFirst)((0, _pascalCase.pascalCase)(e));
|
|
11
15
|
}
|
package/dist/camel-case.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the input string is in camel case.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Camel case is defined as a lowercase first letter followed by any number of uppercase letters and digits - "thisIsAnExample".
|
|
6
|
+
*
|
|
7
|
+
* @param input - The input string to check.
|
|
8
|
+
* @returns True if the input is in camel case, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isCamelCase(input: string | undefined): boolean;
|
|
1
11
|
/**
|
|
2
12
|
* Convert the input string to camel case.
|
|
3
13
|
*
|
|
4
14
|
* @remarks
|
|
5
|
-
* "thisIsAnExample"
|
|
15
|
+
* Camel case is defined as a lowercase first letter followed by any number of uppercase letters and digits - "thisIsAnExample".
|
|
6
16
|
*
|
|
7
17
|
* @param input - The input string.
|
|
8
18
|
* @returns The camel-cased string.
|
package/dist/camel-case.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lowerCaseFirst as r}from"./lower-case-first";import{pascalCase as
|
|
1
|
+
import{lowerCaseFirst as r}from"./lower-case-first";import{pascalCase as a}from"./pascal-case";export function isCamelCase(e){return e?/^[a-z][a-zA-Z0-9]*$/.test(e):!1}export function camelCase(e){return isCamelCase(e)||e===void 0?e:r(a(e))}
|
package/dist/constant-case.cjs
CHANGED
|
@@ -4,7 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.constantCase = constantCase;
|
|
7
|
+
exports.isConstantCase = isConstantCase;
|
|
8
|
+
var _getWords = require("./get-words.cjs");
|
|
7
9
|
var _snakeCase = require("./snake-case.cjs");
|
|
10
|
+
function isConstantCase(e) {
|
|
11
|
+
return e ? /^[A-Z0-9_]+$/.test(e) : !1;
|
|
12
|
+
}
|
|
8
13
|
function constantCase(e) {
|
|
9
|
-
return e
|
|
14
|
+
return isConstantCase(e) || e === void 0 ? e : (0, _snakeCase.isSnakeCase)(e) ? e.toUpperCase() : (0, _getWords.getWords)(e).join("_").toUpperCase();
|
|
10
15
|
}
|
package/dist/constant-case.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the input string is in constant case.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Constant case is defined as all uppercase letters with underscores separating words - "THIS_IS_AN_EXAMPLE".
|
|
6
|
+
*
|
|
7
|
+
* @param input - The input string to check.
|
|
8
|
+
* @returns True if the input is in constant case, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isConstantCase(input: string | undefined): boolean;
|
|
1
11
|
/**
|
|
2
12
|
* Convert the input string to constant case.
|
|
3
13
|
*
|
|
4
14
|
* @remarks
|
|
5
|
-
* "THIS_IS_AN_EXAMPLE"
|
|
15
|
+
* Constant case is defined as all uppercase letters with underscores separating words - "THIS_IS_AN_EXAMPLE".
|
|
6
16
|
*
|
|
7
17
|
* @param input - The input string.
|
|
8
18
|
* @returns The constant-cased string.
|
package/dist/constant-case.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getWords as s}from"./get-words";import{isSnakeCase as n}from"./snake-case";export function isConstantCase(e){return e?/^[A-Z0-9_]+$/.test(e):!1}export function constantCase(e){return isConstantCase(e)||e===void 0?e:n(e)?e.toUpperCase():s(e).join("_").toUpperCase()}
|
package/dist/get-words.cjs
CHANGED
|
@@ -7,6 +7,6 @@ exports.CASE_SPLIT_PATTERN = void 0;
|
|
|
7
7
|
exports.getWords = getWords;
|
|
8
8
|
const CASE_SPLIT_PATTERN = exports.CASE_SPLIT_PATTERN = /[A-Z]?[a-z]+|\d+|[A-Z]+(?![a-z])/g;
|
|
9
9
|
function getWords(r) {
|
|
10
|
-
if (r.length >
|
|
10
|
+
if (r.length > 5e3) throw new Error("The regular expression parameter of `get-words` can't handle strings longer than 2000 characters");
|
|
11
11
|
return [...(r.match(CASE_SPLIT_PATTERN) ?? [])];
|
|
12
12
|
}
|
package/dist/get-words.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CASE_SPLIT_PATTERN=/[A-Z]?[a-z]+|\d+|[A-Z]+(?![a-z])/g;export function getWords(r){if(r.length>
|
|
1
|
+
export const CASE_SPLIT_PATTERN=/[A-Z]?[a-z]+|\d+|[A-Z]+(?![a-z])/g;export function getWords(r){if(r.length>5e3)throw new Error("The regular expression parameter of `get-words` can't handle strings longer than 2000 characters");return[...r.match(CASE_SPLIT_PATTERN)??[]]}
|
package/dist/kebab-case.cjs
CHANGED
|
@@ -3,9 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.isKebabCase = isKebabCase;
|
|
6
7
|
exports.kebabCase = kebabCase;
|
|
7
8
|
var _getWords = require("./get-words.cjs");
|
|
9
|
+
function isKebabCase(e) {
|
|
10
|
+
return e ? /^[a-z]+(?:-[a-z0-9]+)*$/.test(e) : !1;
|
|
11
|
+
}
|
|
8
12
|
function kebabCase(e) {
|
|
13
|
+
if (isKebabCase(e) || e === void 0) return e;
|
|
9
14
|
const r = e ? (0, _getWords.getWords)(e) : [];
|
|
10
15
|
return r.length === 0 ? "" : r.join("-").toLowerCase();
|
|
11
16
|
}
|
package/dist/kebab-case.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the input string is in kebab case.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Kebab case is defined as all lowercase letters with hyphens separating words - "this-is-an-example".
|
|
6
|
+
*
|
|
7
|
+
* @param input - The input string to check.
|
|
8
|
+
* @returns True if the input is in kebab case, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isKebabCase(input: string | undefined): boolean;
|
|
1
11
|
/**
|
|
2
12
|
* Convert the input string to kebab case.
|
|
3
13
|
*
|
|
4
14
|
* @remarks
|
|
5
|
-
* "this-is-an-example"
|
|
15
|
+
* Kebab case is defined as all lowercase letters with hyphens separating words - "this-is-an-example".
|
|
6
16
|
*
|
|
7
17
|
* @param input - The input string.
|
|
8
18
|
* @returns The kebab-cased string.
|
package/dist/kebab-case.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getWords as
|
|
1
|
+
import{getWords as n}from"./get-words";export function isKebabCase(e){return e?/^[a-z]+(?:-[a-z0-9]+)*$/.test(e):!1}export function kebabCase(e){if(isKebabCase(e)||e===void 0)return e;const r=e?n(e):[];return r.length===0?"":r.join("-").toLowerCase()}
|
package/dist/pascal-case.cjs
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.isPascalCase = isPascalCase;
|
|
6
7
|
exports.pascalCase = pascalCase;
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
var _getWords = require("./get-words.cjs");
|
|
9
|
+
function isPascalCase(e) {
|
|
10
|
+
return e ? /^[A-Z][a-zA-Z0-9]*$/.test(e) : !1;
|
|
11
|
+
}
|
|
12
|
+
function pascalCase(e) {
|
|
13
|
+
return e === void 0 ? e : (0, _getWords.getWords)(e).map(n => n.length > 0 ? n.trim().charAt(0).toUpperCase() + n.trim().slice(1) : "").join("");
|
|
9
14
|
}
|
package/dist/pascal-case.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the input string is in pascal case.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - "ThisIsAnExample".
|
|
6
|
+
*
|
|
7
|
+
* @param input - The input string to check.
|
|
8
|
+
* @returns True if the input is in pascal case, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isPascalCase(input: string | undefined): boolean;
|
|
1
11
|
/**
|
|
2
12
|
* Convert the input string to pascal case.
|
|
3
13
|
*
|
|
4
14
|
* @remarks
|
|
5
|
-
* "ThisIsAnExample"
|
|
15
|
+
* Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - "ThisIsAnExample".
|
|
6
16
|
*
|
|
7
17
|
* @param input - The input string.
|
|
8
18
|
* @returns The pascal-cased string.
|
package/dist/pascal-case.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function
|
|
1
|
+
import{getWords as r}from"./get-words";export function isPascalCase(e){return e?/^[A-Z][a-zA-Z0-9]*$/.test(e):!1}export function pascalCase(e){return e===void 0?e:r(e).map(n=>n.length>0?n.trim().charAt(0).toUpperCase()+n.trim().slice(1):"").join("")}
|
package/dist/snake-case.cjs
CHANGED
|
@@ -3,14 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.isSnakeCase = isSnakeCase;
|
|
6
7
|
exports.snakeCase = snakeCase;
|
|
7
8
|
var _types = require("@stryke/types");
|
|
9
|
+
var _constantCase = require("./constant-case.cjs");
|
|
8
10
|
var _upperCaseFirst = require("./upper-case-first.cjs");
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
function isSnakeCase(e) {
|
|
12
|
+
return e ? /^[a-z]+(?:_[a-z0-9]+)*$/.test(e) : !1;
|
|
13
|
+
}
|
|
14
|
+
function snakeCase(e, n) {
|
|
15
|
+
if (isSnakeCase(e) || e === void 0) return e;
|
|
16
|
+
if ((0, _constantCase.isConstantCase)(e)) return e.toLowerCase();
|
|
17
|
+
const s = e?.replace(/[A-Z]+/g, r => (0, _upperCaseFirst.upperCaseFirst)(r) ?? _types.EMPTY_STRING).split(/(?=[A-Z])|[\s._-]/).map(r => r.toLowerCase()) ?? [];
|
|
18
|
+
if (s.length === 0) return "";
|
|
19
|
+
if (s.length === 1) return s[0];
|
|
20
|
+
const t = s.reduce((r, a) => `${r}_${a.toLowerCase()}`);
|
|
21
|
+
return n?.splitOnNumber === !1 ? t : t.replace(/[A-Z]\d/i, r => `${r[0]}_${r[1]}`);
|
|
16
22
|
}
|
package/dist/snake-case.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
export interface SnakeCaseOptions {
|
|
2
2
|
splitOnNumber: boolean;
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* Check if the input string is in snake case.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Snake case is defined as all lowercase letters with underscores separating words - "this_is_an_example"
|
|
9
|
+
*
|
|
10
|
+
* @param input - The input string to check.
|
|
11
|
+
* @returns True if the input is in snake case, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isSnakeCase(input: string | undefined): boolean;
|
|
4
14
|
/**
|
|
5
15
|
* Convert the input string to snake case.
|
|
6
16
|
*
|
|
7
17
|
* @remarks
|
|
8
|
-
* "this_is_an_example"
|
|
18
|
+
* Snake case is defined as all lowercase letters with underscores separating words - "this_is_an_example"
|
|
9
19
|
*
|
|
10
20
|
* @param input - The input string.
|
|
11
21
|
* @param options - Options to control the behavior of the function.
|
package/dist/snake-case.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EMPTY_STRING as
|
|
1
|
+
import{EMPTY_STRING as o}from"@stryke/types";import{isConstantCase as i}from"./constant-case";import{upperCaseFirst as f}from"./upper-case-first";export function isSnakeCase(e){return e?/^[a-z]+(?:_[a-z0-9]+)*$/.test(e):!1}export function snakeCase(e,n){if(isSnakeCase(e)||e===void 0)return e;if(i(e))return e.toLowerCase();const s=e?.replace(/[A-Z]+/g,r=>f(r)??o).split(/(?=[A-Z])|[\s._-]/).map(r=>r.toLowerCase())??[];if(s.length===0)return"";if(s.length===1)return s[0];const t=s.reduce((r,a)=>`${r}_${a.toLowerCase()}`);return n?.splitOnNumber===!1?t:t.replace(/[A-Z]\d/i,r=>`${r[0]}_${r[1]}`)}
|
package/dist/start-case.cjs
CHANGED
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.isStartCase = isStartCase;
|
|
6
7
|
exports.startCase = startCase;
|
|
7
8
|
var _getWords = require("./get-words.cjs");
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
function isStartCase(e) {
|
|
10
|
+
return e ? /^[A-Z][a-z]*(?: [A-Z][a-z]*)*$/.test(e) : !1;
|
|
11
|
+
}
|
|
12
|
+
function startCase(e) {
|
|
13
|
+
if (isStartCase(e) || e === void 0) return e;
|
|
14
|
+
const s = (0, _getWords.getWords)(e.trim());
|
|
15
|
+
let t = "";
|
|
16
|
+
for (const r of s) r && r[0] && (t && (t += " "), t += r === r.toUpperCase() ? r : r[0].toUpperCase() + r.slice(1).toLowerCase());
|
|
17
|
+
return t;
|
|
14
18
|
}
|
package/dist/start-case.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Check if the input string is in snake case.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
* "This Is An Example"
|
|
5
|
+
* Start case is the naming convention in which each word is written with an initial capital letter - "This Is An Example".
|
|
6
|
+
*
|
|
7
|
+
* @param input - The input string to check.
|
|
8
|
+
* @returns True if the input is in start case, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isStartCase(input: string | undefined): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.
|
|
6
13
|
*
|
|
7
|
-
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Start case is the naming convention in which each word is written with an initial capital letter - "This Is An Example".
|
|
8
16
|
*
|
|
9
17
|
* @example
|
|
10
18
|
* ```ts
|
package/dist/start-case.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getWords as
|
|
1
|
+
import{getWords as o}from"./get-words";export function isStartCase(e){return e?/^[A-Z][a-z]*(?: [A-Z][a-z]*)*$/.test(e):!1}export function startCase(e){if(isStartCase(e)||e===void 0)return e;const s=o(e.trim());let t="";for(const r of s)r&&r[0]&&(t&&(t+=" "),t+=r===r.toUpperCase()?r:r[0].toUpperCase()+r.slice(1).toLowerCase());return t}
|
package/dist/title-case.cjs
CHANGED
|
@@ -4,17 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.LOWER_CASE_WHEN_NOT_FIRST = exports.FORMAT_MAPPING = void 0;
|
|
7
|
+
exports.isTitleCase = isTitleCase;
|
|
7
8
|
exports.titleCase = titleCase;
|
|
8
9
|
var _acronyms = require("./acronyms.cjs");
|
|
9
10
|
var _upperCaseFirst = require("./upper-case-first.cjs");
|
|
10
|
-
const FORMAT_MAPPING = exports.FORMAT_MAPPING = _acronyms.ACRONYMS.reduce((
|
|
11
|
+
const FORMAT_MAPPING = exports.FORMAT_MAPPING = _acronyms.ACRONYMS.reduce((e, t) => (e[t.toLowerCase()] = t, e), {
|
|
11
12
|
cspell: "CSpell",
|
|
12
13
|
eslint: "ESLint",
|
|
13
14
|
nx: "Nx"
|
|
14
15
|
}),
|
|
15
16
|
LOWER_CASE_WHEN_NOT_FIRST = exports.LOWER_CASE_WHEN_NOT_FIRST = ["a", "an", "the", "is", "are", "of", "and", "to", "in", "for", "on", "with", "as", "at", "by"];
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function isTitleCase(e) {
|
|
18
|
+
return e ? e.split(/[\s\-_]+/).filter(Boolean).every((s, n) => Object.values(FORMAT_MAPPING).includes(s) || n > 0 && LOWER_CASE_WHEN_NOT_FIRST.includes(s.toLowerCase()) && s === s.toLowerCase() ? !0 : /^[A-Z][a-z0-9]*$/.test(s)) : !1;
|
|
19
|
+
}
|
|
20
|
+
function titleCase(e, t = {}) {
|
|
21
|
+
if (isTitleCase(e) || e === void 0) return e;
|
|
22
|
+
const s = n => n.toLowerCase().split(/[\s\-_]+/).filter(Boolean).map((r, i) => !t.skipLowerCaseWhenNotFirst && LOWER_CASE_WHEN_NOT_FIRST.includes(r.toLowerCase()) && i > 0 ? r.toLowerCase() : !t.skipFormatMapping && Object.keys(FORMAT_MAPPING).includes(r.toLowerCase()) ? FORMAT_MAPPING[r.toLowerCase()] : t.mapping && Object.keys(t.mapping).includes(r.toLowerCase()) ? t.mapping[r.toLowerCase()] : `${(0, _upperCaseFirst.upperCaseFirst)(r.toLowerCase())}`).join(" ");
|
|
23
|
+
return e.split(/\s+-\s+/).map(n => s(n)).join(" - ");
|
|
20
24
|
}
|
package/dist/title-case.d.ts
CHANGED
|
@@ -28,13 +28,23 @@ export interface TitleCaseOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
mapping?: Record<string, string>;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if the input string is in title case.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Title case is defined as a string where each word is separated by spaces, and starts with an uppercase letter followed by lowercase letters - "This Is An Example".
|
|
36
|
+
*
|
|
37
|
+
* @param input - The input string to check.
|
|
38
|
+
* @returns True if the input is in title case, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isTitleCase(input: string | undefined): boolean;
|
|
31
41
|
/**
|
|
32
42
|
* Convert the input string to title case.
|
|
33
43
|
*
|
|
34
44
|
* @remarks
|
|
35
|
-
* "This Is An Example"
|
|
45
|
+
* Title case is defined as a string where each word is separated by spaces, and starts with an uppercase letter followed by lowercase letters - "This Is An Example".
|
|
36
46
|
*
|
|
37
47
|
* @param input - The input string.
|
|
38
48
|
* @returns The title cased string.
|
|
39
49
|
*/
|
|
40
|
-
export declare function titleCase<T extends string | undefined>(input
|
|
50
|
+
export declare function titleCase<T extends string | undefined>(input: T, options?: TitleCaseOptions): T;
|
package/dist/title-case.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ACRONYMS as
|
|
1
|
+
import{ACRONYMS as o}from"./acronyms";import{upperCaseFirst as a}from"./upper-case-first";export const FORMAT_MAPPING=o.reduce((e,t)=>(e[t.toLowerCase()]=t,e),{cspell:"CSpell",eslint:"ESLint",nx:"Nx"}),LOWER_CASE_WHEN_NOT_FIRST=["a","an","the","is","are","of","and","to","in","for","on","with","as","at","by"];export function isTitleCase(e){return e?e.split(/[\s\-_]+/).filter(Boolean).every((s,n)=>Object.values(FORMAT_MAPPING).includes(s)||n>0&&LOWER_CASE_WHEN_NOT_FIRST.includes(s.toLowerCase())&&s===s.toLowerCase()?!0:/^[A-Z][a-z0-9]*$/.test(s)):!1}export function titleCase(e,t={}){if(isTitleCase(e)||e===void 0)return e;const s=n=>n.toLowerCase().split(/[\s\-_]+/).filter(Boolean).map((r,i)=>!t.skipLowerCaseWhenNotFirst&&LOWER_CASE_WHEN_NOT_FIRST.includes(r.toLowerCase())&&i>0?r.toLowerCase():!t.skipFormatMapping&&Object.keys(FORMAT_MAPPING).includes(r.toLowerCase())?FORMAT_MAPPING[r.toLowerCase()]:t.mapping&&Object.keys(t.mapping).includes(r.toLowerCase())?t.mapping[r.toLowerCase()]:`${a(r.toLowerCase())}`).join(" ");return e.split(/\s+-\s+/).map(n=>s(n)).join(" - ")}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/string-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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.7.
|
|
13
|
+
"dependencies": { "@stryke/helpers": "^0.7.1", "@stryke/types": "^0.8.8" },
|
|
14
14
|
"devDependencies": {},
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"files": ["dist/**/*"],
|
|
@@ -333,5 +333,5 @@
|
|
|
333
333
|
"main": "./dist/index.cjs",
|
|
334
334
|
"module": "./dist/index.mjs",
|
|
335
335
|
"types": "./dist/index.d.ts",
|
|
336
|
-
"gitHead": "
|
|
336
|
+
"gitHead": "65b0557df259542217c34e7e93413b662359e3d3"
|
|
337
337
|
}
|