@stryke/string-format 0.13.2 → 0.13.4
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/CHANGELOG.md +14 -0
- package/dist/acronyms.cjs +411 -1
- package/dist/acronyms.mjs +407 -1
- package/dist/acronyms.mjs.map +1 -1
- package/dist/articles.cjs +10 -1
- package/dist/articles.mjs +9 -1
- package/dist/articles.mjs.map +1 -1
- package/dist/camel-case.cjs +32 -1
- package/dist/camel-case.mjs +31 -1
- package/dist/camel-case.mjs.map +1 -1
- package/dist/combine.cjs +15 -1
- package/dist/combine.mjs +14 -1
- package/dist/combine.mjs.map +1 -1
- package/dist/conjunctions.cjs +32 -1
- package/dist/conjunctions.mjs +31 -1
- package/dist/conjunctions.mjs.map +1 -1
- package/dist/constant-case.cjs +32 -1
- package/dist/constant-case.mjs +31 -1
- package/dist/constant-case.mjs.map +1 -1
- package/dist/deburr.cjs +28 -1
- package/dist/deburr.mjs +28 -1
- package/dist/deburr.mjs.map +1 -1
- package/dist/decamelize.cjs +14 -1
- package/dist/decamelize.mjs +13 -1
- package/dist/decamelize.mjs.map +1 -1
- package/dist/escape.cjs +49 -1
- package/dist/escape.mjs +47 -1
- package/dist/escape.mjs.map +1 -1
- package/dist/format-special-cases.cjs +33 -1
- package/dist/format-special-cases.mjs +33 -1
- package/dist/format-special-cases.mjs.map +1 -1
- package/dist/get-words.cjs +40 -1
- package/dist/get-words.mjs +37 -1
- package/dist/get-words.mjs.map +1 -1
- package/dist/helpers/src/remove-accents.cjs +415 -1
- package/dist/helpers/src/remove-accents.mjs +414 -1
- package/dist/helpers/src/remove-accents.mjs.map +1 -1
- package/dist/index.cjs +75 -1
- package/dist/index.mjs +30 -1
- package/dist/kebab-case.cjs +34 -1
- package/dist/kebab-case.mjs +33 -1
- package/dist/kebab-case.mjs.map +1 -1
- package/dist/lower-case-first.cjs +17 -1
- package/dist/lower-case-first.mjs +16 -1
- package/dist/lower-case-first.mjs.map +1 -1
- package/dist/normalize-email.cjs +31 -1
- package/dist/normalize-email.mjs +30 -1
- package/dist/normalize-email.mjs.map +1 -1
- package/dist/package.cjs +124 -1
- package/dist/package.mjs +120 -1
- package/dist/package.mjs.map +1 -1
- package/dist/pad.cjs +25 -1
- package/dist/pad.mjs +24 -1
- package/dist/pad.mjs.map +1 -1
- package/dist/pascal-case.cjs +32 -1
- package/dist/pascal-case.mjs +31 -1
- package/dist/pascal-case.mjs.map +1 -1
- package/dist/period-split.cjs +38 -1
- package/dist/period-split.mjs +37 -1
- package/dist/period-split.mjs.map +1 -1
- package/dist/prepositions.cjs +68 -1
- package/dist/prepositions.mjs +67 -1
- package/dist/prepositions.mjs.map +1 -1
- package/dist/pretty-bytes.cjs +129 -1
- package/dist/pretty-bytes.mjs +127 -1
- package/dist/pretty-bytes.mjs.map +1 -1
- package/dist/snake-case.cjs +42 -1
- package/dist/snake-case.mjs +41 -1
- package/dist/snake-case.mjs.map +1 -1
- package/dist/special-cases.cjs +53 -1
- package/dist/special-cases.mjs +52 -1
- package/dist/special-cases.mjs.map +1 -1
- package/dist/start-case.cjs +46 -1
- package/dist/start-case.mjs +45 -1
- package/dist/start-case.mjs.map +1 -1
- package/dist/strip-indents.cjs +24 -3
- package/dist/strip-indents.mjs +23 -3
- package/dist/strip-indents.mjs.map +1 -1
- package/dist/title-case.cjs +19 -1
- package/dist/title-case.mjs +19 -1
- package/dist/title-case.mjs.map +1 -1
- package/dist/types/src/base.cjs +6 -1
- package/dist/types/src/base.mjs +5 -1
- package/dist/types/src/base.mjs.map +1 -1
- package/dist/unescape.cjs +30 -1
- package/dist/unescape.mjs +29 -1
- package/dist/unescape.mjs.map +1 -1
- package/dist/upper-case-first.cjs +17 -1
- package/dist/upper-case-first.mjs +16 -1
- package/dist/upper-case-first.mjs.map +1 -1
- package/dist/vowels.cjs +40 -1
- package/dist/vowels.mjs +38 -1
- package/dist/vowels.mjs.map +1 -1
- package/package.json +2 -2
package/dist/kebab-case.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kebab-case.mjs","names":[],"sources":["../src/kebab-case.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getWords } from \"./get-words\";\n\n/**\n * Check if the input string is in kebab case.\n *\n * @remarks\n * Kebab case is defined as all lowercase letters with hyphens separating words - \"this-is-an-example\".\n *\n * @param input - The input string to check.\n * @returns True if the input is in kebab case, false otherwise.\n */\nexport function isKebabCase(input: string | undefined): boolean {\n return input ? /^[a-z]+(?:-[a-z0-9]+)*$/.test(input) : false;\n}\n\n/**\n * Convert the input string to kebab case.\n *\n * @remarks\n * Kebab case is defined as all lowercase letters with hyphens separating words - \"this-is-an-example\".\n *\n * @param input - The input string.\n * @returns The kebab-cased string.\n */\nexport function kebabCase<T extends string | undefined>(input: T): T {\n if (isKebabCase(input) || input === undefined) {\n return input;\n }\n\n const parts = input ? getWords(input) : [];\n if (parts.length === 0) {\n return \"\" as T;\n }\n\n return parts.join(\"-\").toLowerCase() as T;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"kebab-case.mjs","names":[],"sources":["../src/kebab-case.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getWords } from \"./get-words\";\n\n/**\n * Check if the input string is in kebab case.\n *\n * @remarks\n * Kebab case is defined as all lowercase letters with hyphens separating words - \"this-is-an-example\".\n *\n * @param input - The input string to check.\n * @returns True if the input is in kebab case, false otherwise.\n */\nexport function isKebabCase(input: string | undefined): boolean {\n return input ? /^[a-z]+(?:-[a-z0-9]+)*$/.test(input) : false;\n}\n\n/**\n * Convert the input string to kebab case.\n *\n * @remarks\n * Kebab case is defined as all lowercase letters with hyphens separating words - \"this-is-an-example\".\n *\n * @param input - The input string.\n * @returns The kebab-cased string.\n */\nexport function kebabCase<T extends string | undefined>(input: T): T {\n if (isKebabCase(input) || input === undefined) {\n return input;\n }\n\n const parts = input ? getWords(input) : [];\n if (parts.length === 0) {\n return \"\" as T;\n }\n\n return parts.join(\"-\").toLowerCase() as T;\n}\n"],"mappings":";;;;;;;;;;;;AA6BA,SAAgB,YAAY,OAAoC;AAC9D,QAAO,QAAQ,0BAA0B,KAAK,MAAM,GAAG;;;;;;;;;;;AAYzD,SAAgB,UAAwC,OAAa;AACnE,KAAI,YAAY,MAAM,IAAI,UAAU,OAClC,QAAO;CAGT,MAAM,QAAQ,QAAQ,SAAS,MAAM,GAAG,EAAE;AAC1C,KAAI,MAAM,WAAW,EACnB,QAAO;AAGT,QAAO,MAAM,KAAK,IAAI,CAAC,aAAa"}
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/lower-case-first.ts
|
|
3
|
+
/**
|
|
4
|
+
* Lower case the first character of an input string.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* "tHISISANEXAMPLE"
|
|
8
|
+
*
|
|
9
|
+
* @param input - The input string.
|
|
10
|
+
* @returns The lower-cased string.
|
|
11
|
+
*/
|
|
12
|
+
function lowerCaseFirst(input) {
|
|
13
|
+
return input ? input.charAt(0).toLowerCase() + input.slice(1) : input;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.lowerCaseFirst = lowerCaseFirst;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/lower-case-first.ts
|
|
2
|
+
/**
|
|
3
|
+
* Lower case the first character of an input string.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* "tHISISANEXAMPLE"
|
|
7
|
+
*
|
|
8
|
+
* @param input - The input string.
|
|
9
|
+
* @returns The lower-cased string.
|
|
10
|
+
*/
|
|
11
|
+
function lowerCaseFirst(input) {
|
|
12
|
+
return input ? input.charAt(0).toLowerCase() + input.slice(1) : input;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { lowerCaseFirst };
|
|
2
17
|
//# sourceMappingURL=lower-case-first.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lower-case-first.mjs","names":[],"sources":["../src/lower-case-first.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Lower case the first character of an input string.\n *\n * @remarks\n * \"tHISISANEXAMPLE\"\n *\n * @param input - The input string.\n * @returns The lower-cased string.\n */\nexport function lowerCaseFirst<T extends string | undefined>(input?: T): T {\n return (input ? input.charAt(0).toLowerCase() + input.slice(1) : input) as T;\n}\n"],"mappings":"AA2BA,SAAgB,
|
|
1
|
+
{"version":3,"file":"lower-case-first.mjs","names":[],"sources":["../src/lower-case-first.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Lower case the first character of an input string.\n *\n * @remarks\n * \"tHISISANEXAMPLE\"\n *\n * @param input - The input string.\n * @returns The lower-cased string.\n */\nexport function lowerCaseFirst<T extends string | undefined>(input?: T): T {\n return (input ? input.charAt(0).toLowerCase() + input.slice(1) : input) as T;\n}\n"],"mappings":";;;;;;;;;;AA2BA,SAAgB,eAA6C,OAAc;AACzE,QAAQ,QAAQ,MAAM,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,MAAM,EAAE,GAAG"}
|
package/dist/normalize-email.cjs
CHANGED
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/normalize-email.ts
|
|
3
|
+
const DOT_REG = /\./g;
|
|
4
|
+
/**
|
|
5
|
+
* 1. Lower-cases whole email.
|
|
6
|
+
* 2. Removes dots ".".
|
|
7
|
+
* 3. Remotes name part after "+".
|
|
8
|
+
* 4. Throws if cannot parse the email.
|
|
9
|
+
*
|
|
10
|
+
* For example, this email
|
|
11
|
+
*
|
|
12
|
+
* Mike.Johnson+twitter\@Gmail.com
|
|
13
|
+
*
|
|
14
|
+
* will be normalized to
|
|
15
|
+
*
|
|
16
|
+
* mikejohnson\@gmail.com
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
const normalizeEmail = (email) => {
|
|
20
|
+
if (!email.includes("@") && !email.includes("+")) throw new Error("invalid_email_format");
|
|
21
|
+
const split = email.split("@").filter(Boolean);
|
|
22
|
+
if (split.length > 1) throw new Error("invalid_email_format");
|
|
23
|
+
const [name, host] = split;
|
|
24
|
+
let [beforePlus] = name.split("+");
|
|
25
|
+
if (!beforePlus) throw new Error("invalid_email_format");
|
|
26
|
+
beforePlus = beforePlus.replace(DOT_REG, "");
|
|
27
|
+
return `${beforePlus.toLowerCase()}@${host.toLowerCase()}`;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.normalizeEmail = normalizeEmail;
|
package/dist/normalize-email.mjs
CHANGED
|
@@ -1,2 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/normalize-email.ts
|
|
2
|
+
const DOT_REG = /\./g;
|
|
3
|
+
/**
|
|
4
|
+
* 1. Lower-cases whole email.
|
|
5
|
+
* 2. Removes dots ".".
|
|
6
|
+
* 3. Remotes name part after "+".
|
|
7
|
+
* 4. Throws if cannot parse the email.
|
|
8
|
+
*
|
|
9
|
+
* For example, this email
|
|
10
|
+
*
|
|
11
|
+
* Mike.Johnson+twitter\@Gmail.com
|
|
12
|
+
*
|
|
13
|
+
* will be normalized to
|
|
14
|
+
*
|
|
15
|
+
* mikejohnson\@gmail.com
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
const normalizeEmail = (email) => {
|
|
19
|
+
if (!email.includes("@") && !email.includes("+")) throw new Error("invalid_email_format");
|
|
20
|
+
const split = email.split("@").filter(Boolean);
|
|
21
|
+
if (split.length > 1) throw new Error("invalid_email_format");
|
|
22
|
+
const [name, host] = split;
|
|
23
|
+
let [beforePlus] = name.split("+");
|
|
24
|
+
if (!beforePlus) throw new Error("invalid_email_format");
|
|
25
|
+
beforePlus = beforePlus.replace(DOT_REG, "");
|
|
26
|
+
return `${beforePlus.toLowerCase()}@${host.toLowerCase()}`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { normalizeEmail };
|
|
2
31
|
//# sourceMappingURL=normalize-email.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-email.mjs","names":[],"sources":["../src/normalize-email.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nconst DOT_REG = /\\./g;\n\n/**\n * 1. Lower-cases whole email.\n * 2. Removes dots \".\".\n * 3. Remotes name part after \"+\".\n * 4. Throws if cannot parse the email.\n *\n * For example, this email\n *\n * Mike.Johnson+twitter\\@Gmail.com\n *\n * will be normalized to\n *\n * mikejohnson\\@gmail.com\n *\n */\nexport const normalizeEmail = (email: string) => {\n if (!email.includes(\"@\") && !email.includes(\"+\")) {\n throw new Error(\"invalid_email_format\");\n }\n\n const split = email.split(\"@\").filter(Boolean);\n if (split.length > 1) {\n throw new Error(\"invalid_email_format\");\n }\n\n const [name, host] = split;\n\n let [beforePlus] = name!.split(\"+\");\n if (!beforePlus) {\n throw new Error(\"invalid_email_format\");\n }\n\n beforePlus = beforePlus.replace(DOT_REG, \"\");\n const result = `${beforePlus.toLowerCase()}@${host!.toLowerCase()}`;\n Number(result);\n\n return result;\n};\n"],"mappings":"AAkBA,MAAM,
|
|
1
|
+
{"version":3,"file":"normalize-email.mjs","names":[],"sources":["../src/normalize-email.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nconst DOT_REG = /\\./g;\n\n/**\n * 1. Lower-cases whole email.\n * 2. Removes dots \".\".\n * 3. Remotes name part after \"+\".\n * 4. Throws if cannot parse the email.\n *\n * For example, this email\n *\n * Mike.Johnson+twitter\\@Gmail.com\n *\n * will be normalized to\n *\n * mikejohnson\\@gmail.com\n *\n */\nexport const normalizeEmail = (email: string) => {\n if (!email.includes(\"@\") && !email.includes(\"+\")) {\n throw new Error(\"invalid_email_format\");\n }\n\n const split = email.split(\"@\").filter(Boolean);\n if (split.length > 1) {\n throw new Error(\"invalid_email_format\");\n }\n\n const [name, host] = split;\n\n let [beforePlus] = name!.split(\"+\");\n if (!beforePlus) {\n throw new Error(\"invalid_email_format\");\n }\n\n beforePlus = beforePlus.replace(DOT_REG, \"\");\n const result = `${beforePlus.toLowerCase()}@${host!.toLowerCase()}`;\n Number(result);\n\n return result;\n};\n"],"mappings":";AAkBA,MAAM,UAAU;;;;;;;;;;;;;;;;AAiBhB,MAAa,kBAAkB,UAAkB;AAC/C,KAAI,CAAC,MAAM,SAAS,IAAI,IAAI,CAAC,MAAM,SAAS,IAAI,CAC9C,OAAM,IAAI,MAAM,uBAAuB;CAGzC,MAAM,QAAQ,MAAM,MAAM,IAAI,CAAC,OAAO,QAAQ;AAC9C,KAAI,MAAM,SAAS,EACjB,OAAM,IAAI,MAAM,uBAAuB;CAGzC,MAAM,CAAC,MAAM,QAAQ;CAErB,IAAI,CAAC,cAAc,KAAM,MAAM,IAAI;AACnC,KAAI,CAAC,WACH,OAAM,IAAI,MAAM,uBAAuB;AAGzC,cAAa,WAAW,QAAQ,SAAS,GAAG;AAI5C,QAHe,GAAG,WAAW,aAAa,CAAC,GAAG,KAAM,aAAa"}
|
package/dist/package.cjs
CHANGED
|
@@ -1 +1,124 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/package.ts
|
|
3
|
+
/**
|
|
4
|
+
* Check if a package name has a version
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* hasPackageVersion("lodash@4.17.21");
|
|
9
|
+
* // => true
|
|
10
|
+
* hasPackageVersion("@stryke/core@4.17.21");
|
|
11
|
+
* // => true
|
|
12
|
+
* hasPackageVersion("lodash");
|
|
13
|
+
* // => false
|
|
14
|
+
* hasPackageVersion("@stryke/core");
|
|
15
|
+
* // => false
|
|
16
|
+
* hasPackageVersion("lodash/module");
|
|
17
|
+
* // => false
|
|
18
|
+
* hasPackageVersion("@stryke/core/module");
|
|
19
|
+
* // => false
|
|
20
|
+
* hasPackageVersion("lodash/module@4.17.21");
|
|
21
|
+
* // => true
|
|
22
|
+
* hasPackageVersion("@stryke/core/module@4.17.21");
|
|
23
|
+
* // => true
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param value - The package name with version
|
|
27
|
+
* @returns Whether the package name has a version
|
|
28
|
+
*/
|
|
29
|
+
function hasPackageVersion(value) {
|
|
30
|
+
return /^.[^\n\r@\u2028\u2029]*@.*$/.test(value);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Remove the version from a package name (if it exists)
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* removePackageVersion("lodash@4.17.21");
|
|
38
|
+
* // => "lodash"
|
|
39
|
+
* removePackageVersion("@stryke/core@4.17.21");
|
|
40
|
+
* // => "@stryke/core"
|
|
41
|
+
* removePackageVersion("lodash");
|
|
42
|
+
* // => "lodash"
|
|
43
|
+
* removePackageVersion("@stryke/core");
|
|
44
|
+
* // => "@stryke/core"
|
|
45
|
+
* getPackageName("lodash/module");
|
|
46
|
+
* // => "lodash/module"
|
|
47
|
+
* getPackageName("@stryke/core/module");
|
|
48
|
+
* // => "@stryke/core/module"
|
|
49
|
+
* getPackageName("lodash/module@4.17.21");
|
|
50
|
+
* // => "lodash/module"
|
|
51
|
+
* getPackageName("@stryke/core/module@4.17.21");
|
|
52
|
+
* // => "@stryke/core/module"
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @param value - The package name with version
|
|
56
|
+
* @returns The package name without version
|
|
57
|
+
*/
|
|
58
|
+
function removePackageVersion(value) {
|
|
59
|
+
return hasPackageVersion(value) ? value.substring(0, value.lastIndexOf("@")) : value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the package name from a scoped package string
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* getPackageName("lodash@4.17.21");
|
|
67
|
+
* // => "lodash"
|
|
68
|
+
* getPackageName("@stryke/core@4.17.21");
|
|
69
|
+
* // => "@stryke/core"
|
|
70
|
+
* getPackageName("lodash");
|
|
71
|
+
* // => "lodash"
|
|
72
|
+
* getPackageName("@stryke/core");
|
|
73
|
+
* // => "@stryke/core"
|
|
74
|
+
* getPackageName("lodash/module");
|
|
75
|
+
* // => "lodash"
|
|
76
|
+
* getPackageName("@stryke/core/module");
|
|
77
|
+
* // => "@stryke/core"
|
|
78
|
+
* getPackageName("lodash/module@4.17.21");
|
|
79
|
+
* // => "lodash"
|
|
80
|
+
* getPackageName("@stryke/core/module@4.17.21");
|
|
81
|
+
* // => "@stryke/core"
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @param value - The scoped package string
|
|
85
|
+
* @returns The package name without the scope
|
|
86
|
+
*/
|
|
87
|
+
function getPackageName(value) {
|
|
88
|
+
return /^[^\n\r/\u2028\u2029]*\/.[^\n\r/\u2028\u2029]*\/.*$/.test(value) ? value.substring(0, value.lastIndexOf("/")) : removePackageVersion(value);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the package version from a scoped package string
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* getPackageName("lodash@4.17.21");
|
|
96
|
+
* // => "4.17.21"
|
|
97
|
+
* getPackageName("@stryke/core@4.17.21");
|
|
98
|
+
* // => "4.17.21"
|
|
99
|
+
* getPackageName("lodash");
|
|
100
|
+
* // => undefined
|
|
101
|
+
* getPackageName("@stryke/core");
|
|
102
|
+
* // => undefined
|
|
103
|
+
* getPackageName("lodash/module");
|
|
104
|
+
* // => undefined
|
|
105
|
+
* getPackageName("@stryke/core/module");
|
|
106
|
+
* // => undefined
|
|
107
|
+
* getPackageName("lodash/module@4.17.21");
|
|
108
|
+
* // => "4.17.21"
|
|
109
|
+
* getPackageName("@stryke/core/module@4.17.21");
|
|
110
|
+
* // => "4.17.21"
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param value - The scoped package string
|
|
114
|
+
* @returns The package version without the package name if it exists. If not, returns undefined.
|
|
115
|
+
*/
|
|
116
|
+
function getPackageVersion(value) {
|
|
117
|
+
return hasPackageVersion(value) ? value.replace(/^.+@/, "") : void 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
exports.getPackageName = getPackageName;
|
|
122
|
+
exports.getPackageVersion = getPackageVersion;
|
|
123
|
+
exports.hasPackageVersion = hasPackageVersion;
|
|
124
|
+
exports.removePackageVersion = removePackageVersion;
|
package/dist/package.mjs
CHANGED
|
@@ -1,2 +1,121 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/package.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if a package name has a version
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* hasPackageVersion("lodash@4.17.21");
|
|
8
|
+
* // => true
|
|
9
|
+
* hasPackageVersion("@stryke/core@4.17.21");
|
|
10
|
+
* // => true
|
|
11
|
+
* hasPackageVersion("lodash");
|
|
12
|
+
* // => false
|
|
13
|
+
* hasPackageVersion("@stryke/core");
|
|
14
|
+
* // => false
|
|
15
|
+
* hasPackageVersion("lodash/module");
|
|
16
|
+
* // => false
|
|
17
|
+
* hasPackageVersion("@stryke/core/module");
|
|
18
|
+
* // => false
|
|
19
|
+
* hasPackageVersion("lodash/module@4.17.21");
|
|
20
|
+
* // => true
|
|
21
|
+
* hasPackageVersion("@stryke/core/module@4.17.21");
|
|
22
|
+
* // => true
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param value - The package name with version
|
|
26
|
+
* @returns Whether the package name has a version
|
|
27
|
+
*/
|
|
28
|
+
function hasPackageVersion(value) {
|
|
29
|
+
return /^.[^\n\r@\u2028\u2029]*@.*$/.test(value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Remove the version from a package name (if it exists)
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* removePackageVersion("lodash@4.17.21");
|
|
37
|
+
* // => "lodash"
|
|
38
|
+
* removePackageVersion("@stryke/core@4.17.21");
|
|
39
|
+
* // => "@stryke/core"
|
|
40
|
+
* removePackageVersion("lodash");
|
|
41
|
+
* // => "lodash"
|
|
42
|
+
* removePackageVersion("@stryke/core");
|
|
43
|
+
* // => "@stryke/core"
|
|
44
|
+
* getPackageName("lodash/module");
|
|
45
|
+
* // => "lodash/module"
|
|
46
|
+
* getPackageName("@stryke/core/module");
|
|
47
|
+
* // => "@stryke/core/module"
|
|
48
|
+
* getPackageName("lodash/module@4.17.21");
|
|
49
|
+
* // => "lodash/module"
|
|
50
|
+
* getPackageName("@stryke/core/module@4.17.21");
|
|
51
|
+
* // => "@stryke/core/module"
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param value - The package name with version
|
|
55
|
+
* @returns The package name without version
|
|
56
|
+
*/
|
|
57
|
+
function removePackageVersion(value) {
|
|
58
|
+
return hasPackageVersion(value) ? value.substring(0, value.lastIndexOf("@")) : value;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the package name from a scoped package string
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* getPackageName("lodash@4.17.21");
|
|
66
|
+
* // => "lodash"
|
|
67
|
+
* getPackageName("@stryke/core@4.17.21");
|
|
68
|
+
* // => "@stryke/core"
|
|
69
|
+
* getPackageName("lodash");
|
|
70
|
+
* // => "lodash"
|
|
71
|
+
* getPackageName("@stryke/core");
|
|
72
|
+
* // => "@stryke/core"
|
|
73
|
+
* getPackageName("lodash/module");
|
|
74
|
+
* // => "lodash"
|
|
75
|
+
* getPackageName("@stryke/core/module");
|
|
76
|
+
* // => "@stryke/core"
|
|
77
|
+
* getPackageName("lodash/module@4.17.21");
|
|
78
|
+
* // => "lodash"
|
|
79
|
+
* getPackageName("@stryke/core/module@4.17.21");
|
|
80
|
+
* // => "@stryke/core"
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @param value - The scoped package string
|
|
84
|
+
* @returns The package name without the scope
|
|
85
|
+
*/
|
|
86
|
+
function getPackageName(value) {
|
|
87
|
+
return /^[^\n\r/\u2028\u2029]*\/.[^\n\r/\u2028\u2029]*\/.*$/.test(value) ? value.substring(0, value.lastIndexOf("/")) : removePackageVersion(value);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the package version from a scoped package string
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* getPackageName("lodash@4.17.21");
|
|
95
|
+
* // => "4.17.21"
|
|
96
|
+
* getPackageName("@stryke/core@4.17.21");
|
|
97
|
+
* // => "4.17.21"
|
|
98
|
+
* getPackageName("lodash");
|
|
99
|
+
* // => undefined
|
|
100
|
+
* getPackageName("@stryke/core");
|
|
101
|
+
* // => undefined
|
|
102
|
+
* getPackageName("lodash/module");
|
|
103
|
+
* // => undefined
|
|
104
|
+
* getPackageName("@stryke/core/module");
|
|
105
|
+
* // => undefined
|
|
106
|
+
* getPackageName("lodash/module@4.17.21");
|
|
107
|
+
* // => "4.17.21"
|
|
108
|
+
* getPackageName("@stryke/core/module@4.17.21");
|
|
109
|
+
* // => "4.17.21"
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @param value - The scoped package string
|
|
113
|
+
* @returns The package version without the package name if it exists. If not, returns undefined.
|
|
114
|
+
*/
|
|
115
|
+
function getPackageVersion(value) {
|
|
116
|
+
return hasPackageVersion(value) ? value.replace(/^.+@/, "") : void 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
export { getPackageName, getPackageVersion, hasPackageVersion, removePackageVersion };
|
|
2
121
|
//# sourceMappingURL=package.mjs.map
|
package/dist/package.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.mjs","names":[],"sources":["../src/package.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Check if a package name has a version\n *\n * @example\n * ```typescript\n * hasPackageVersion(\"lodash@4.17.21\");\n * // => true\n * hasPackageVersion(\"@stryke/core@4.17.21\");\n * // => true\n * hasPackageVersion(\"lodash\");\n * // => false\n * hasPackageVersion(\"@stryke/core\");\n * // => false\n * hasPackageVersion(\"lodash/module\");\n * // => false\n * hasPackageVersion(\"@stryke/core/module\");\n * // => false\n * hasPackageVersion(\"lodash/module@4.17.21\");\n * // => true\n * hasPackageVersion(\"@stryke/core/module@4.17.21\");\n * // => true\n * ```\n *\n * @param value - The package name with version\n * @returns Whether the package name has a version\n */\nexport function hasPackageVersion(value: string): boolean {\n return /^.[^\\n\\r@\\u2028\\u2029]*@.*$/.test(value);\n}\n\n/**\n * Remove the version from a package name (if it exists)\n *\n * @example\n * ```typescript\n * removePackageVersion(\"lodash@4.17.21\");\n * // => \"lodash\"\n * removePackageVersion(\"@stryke/core@4.17.21\");\n * // => \"@stryke/core\"\n * removePackageVersion(\"lodash\");\n * // => \"lodash\"\n * removePackageVersion(\"@stryke/core\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash/module\");\n * // => \"lodash/module\"\n * getPackageName(\"@stryke/core/module\");\n * // => \"@stryke/core/module\"\n * getPackageName(\"lodash/module@4.17.21\");\n * // => \"lodash/module\"\n * getPackageName(\"@stryke/core/module@4.17.21\");\n * // => \"@stryke/core/module\"\n * ```\n *\n * @param value - The package name with version\n * @returns The package name without version\n */\nexport function removePackageVersion(value: string) {\n return hasPackageVersion(value)\n ? value.substring(0, value.lastIndexOf(\"@\"))\n : value;\n}\n\n/**\n * Get the package name from a scoped package string\n *\n * @example\n * ```typescript\n * getPackageName(\"lodash@4.17.21\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core@4.17.21\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash/module\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core/module\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash/module@4.17.21\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core/module@4.17.21\");\n * // => \"@stryke/core\"\n * ```\n *\n * @param value - The scoped package string\n * @returns The package name without the scope\n */\nexport function getPackageName(value: string) {\n return /^[^\\n\\r/\\u2028\\u2029]*\\/.[^\\n\\r/\\u2028\\u2029]*\\/.*$/.test(value)\n ? value.substring(0, value.lastIndexOf(\"/\"))\n : removePackageVersion(value);\n}\n\n/**\n * Get the package version from a scoped package string\n *\n * @example\n * ```typescript\n * getPackageName(\"lodash@4.17.21\");\n * // => \"4.17.21\"\n * getPackageName(\"@stryke/core@4.17.21\");\n * // => \"4.17.21\"\n * getPackageName(\"lodash\");\n * // => undefined\n * getPackageName(\"@stryke/core\");\n * // => undefined\n * getPackageName(\"lodash/module\");\n * // => undefined\n * getPackageName(\"@stryke/core/module\");\n * // => undefined\n * getPackageName(\"lodash/module@4.17.21\");\n * // => \"4.17.21\"\n * getPackageName(\"@stryke/core/module@4.17.21\");\n * // => \"4.17.21\"\n * ```\n *\n * @param value - The scoped package string\n * @returns The package version without the package name if it exists. If not, returns undefined.\n */\nexport function getPackageVersion(value: string): string | undefined {\n return hasPackageVersion(value) ? value.replace(/^.+@/, \"\") : undefined;\n}\n"],"mappings":"AA4CA,SAAgB,
|
|
1
|
+
{"version":3,"file":"package.mjs","names":[],"sources":["../src/package.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Check if a package name has a version\n *\n * @example\n * ```typescript\n * hasPackageVersion(\"lodash@4.17.21\");\n * // => true\n * hasPackageVersion(\"@stryke/core@4.17.21\");\n * // => true\n * hasPackageVersion(\"lodash\");\n * // => false\n * hasPackageVersion(\"@stryke/core\");\n * // => false\n * hasPackageVersion(\"lodash/module\");\n * // => false\n * hasPackageVersion(\"@stryke/core/module\");\n * // => false\n * hasPackageVersion(\"lodash/module@4.17.21\");\n * // => true\n * hasPackageVersion(\"@stryke/core/module@4.17.21\");\n * // => true\n * ```\n *\n * @param value - The package name with version\n * @returns Whether the package name has a version\n */\nexport function hasPackageVersion(value: string): boolean {\n return /^.[^\\n\\r@\\u2028\\u2029]*@.*$/.test(value);\n}\n\n/**\n * Remove the version from a package name (if it exists)\n *\n * @example\n * ```typescript\n * removePackageVersion(\"lodash@4.17.21\");\n * // => \"lodash\"\n * removePackageVersion(\"@stryke/core@4.17.21\");\n * // => \"@stryke/core\"\n * removePackageVersion(\"lodash\");\n * // => \"lodash\"\n * removePackageVersion(\"@stryke/core\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash/module\");\n * // => \"lodash/module\"\n * getPackageName(\"@stryke/core/module\");\n * // => \"@stryke/core/module\"\n * getPackageName(\"lodash/module@4.17.21\");\n * // => \"lodash/module\"\n * getPackageName(\"@stryke/core/module@4.17.21\");\n * // => \"@stryke/core/module\"\n * ```\n *\n * @param value - The package name with version\n * @returns The package name without version\n */\nexport function removePackageVersion(value: string) {\n return hasPackageVersion(value)\n ? value.substring(0, value.lastIndexOf(\"@\"))\n : value;\n}\n\n/**\n * Get the package name from a scoped package string\n *\n * @example\n * ```typescript\n * getPackageName(\"lodash@4.17.21\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core@4.17.21\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash/module\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core/module\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash/module@4.17.21\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core/module@4.17.21\");\n * // => \"@stryke/core\"\n * ```\n *\n * @param value - The scoped package string\n * @returns The package name without the scope\n */\nexport function getPackageName(value: string) {\n return /^[^\\n\\r/\\u2028\\u2029]*\\/.[^\\n\\r/\\u2028\\u2029]*\\/.*$/.test(value)\n ? value.substring(0, value.lastIndexOf(\"/\"))\n : removePackageVersion(value);\n}\n\n/**\n * Get the package version from a scoped package string\n *\n * @example\n * ```typescript\n * getPackageName(\"lodash@4.17.21\");\n * // => \"4.17.21\"\n * getPackageName(\"@stryke/core@4.17.21\");\n * // => \"4.17.21\"\n * getPackageName(\"lodash\");\n * // => undefined\n * getPackageName(\"@stryke/core\");\n * // => undefined\n * getPackageName(\"lodash/module\");\n * // => undefined\n * getPackageName(\"@stryke/core/module\");\n * // => undefined\n * getPackageName(\"lodash/module@4.17.21\");\n * // => \"4.17.21\"\n * getPackageName(\"@stryke/core/module@4.17.21\");\n * // => \"4.17.21\"\n * ```\n *\n * @param value - The scoped package string\n * @returns The package version without the package name if it exists. If not, returns undefined.\n */\nexport function getPackageVersion(value: string): string | undefined {\n return hasPackageVersion(value) ? value.replace(/^.+@/, \"\") : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,kBAAkB,OAAwB;AACxD,QAAO,8BAA8B,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BlD,SAAgB,qBAAqB,OAAe;AAClD,QAAO,kBAAkB,MAAM,GAC3B,MAAM,UAAU,GAAG,MAAM,YAAY,IAAI,CAAC,GAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BN,SAAgB,eAAe,OAAe;AAC5C,QAAO,sDAAsD,KAAK,MAAM,GACpE,MAAM,UAAU,GAAG,MAAM,YAAY,IAAI,CAAC,GAC1C,qBAAqB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BjC,SAAgB,kBAAkB,OAAmC;AACnE,QAAO,kBAAkB,MAAM,GAAG,MAAM,QAAQ,QAAQ,GAAG,GAAG"}
|
package/dist/pad.cjs
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/pad.ts
|
|
3
|
+
/**
|
|
4
|
+
* Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.
|
|
5
|
+
* If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @param str - The string to pad.
|
|
8
|
+
* @param length - The length of the resulting string once padded.
|
|
9
|
+
* @param chars - The character(s) to use for padding.
|
|
10
|
+
* @returns The padded string, or the original string if padding is not required.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const result1 = pad('abc', 8); // result will be ' abc '
|
|
15
|
+
* const result2 = pad('abc', 8, '_-'); // result will be '_-abc_-_'
|
|
16
|
+
* const result3 = pad('abc', 3); // result will be 'abc'
|
|
17
|
+
* const result4 = pad('abc', 2); // result will be 'abc'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
function pad(str, length, chars = " ") {
|
|
21
|
+
return str.padStart(Math.floor((length - str.length) / 2) + str.length, chars).padEnd(length, chars);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.pad = pad;
|
package/dist/pad.mjs
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/pad.ts
|
|
2
|
+
/**
|
|
3
|
+
* Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.
|
|
4
|
+
* If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.
|
|
5
|
+
*
|
|
6
|
+
* @param str - The string to pad.
|
|
7
|
+
* @param length - The length of the resulting string once padded.
|
|
8
|
+
* @param chars - The character(s) to use for padding.
|
|
9
|
+
* @returns The padded string, or the original string if padding is not required.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const result1 = pad('abc', 8); // result will be ' abc '
|
|
14
|
+
* const result2 = pad('abc', 8, '_-'); // result will be '_-abc_-_'
|
|
15
|
+
* const result3 = pad('abc', 3); // result will be 'abc'
|
|
16
|
+
* const result4 = pad('abc', 2); // result will be 'abc'
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function pad(str, length, chars = " ") {
|
|
20
|
+
return str.padStart(Math.floor((length - str.length) / 2) + str.length, chars).padEnd(length, chars);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { pad };
|
|
2
25
|
//# sourceMappingURL=pad.mjs.map
|
package/dist/pad.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pad.mjs","names":[],"sources":["../src/pad.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.\n * If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.\n *\n * @param str - The string to pad.\n * @param length - The length of the resulting string once padded.\n * @param chars - The character(s) to use for padding.\n * @returns The padded string, or the original string if padding is not required.\n *\n * @example\n * ```ts\n * const result1 = pad('abc', 8); // result will be ' abc '\n * const result2 = pad('abc', 8, '_-'); // result will be '_-abc_-_'\n * const result3 = pad('abc', 3); // result will be 'abc'\n * const result4 = pad('abc', 2); // result will be 'abc'\n * ```\n */\nexport function pad(str: string, length: number, chars = \" \"): string {\n return str\n .padStart(Math.floor((length - str.length) / 2) + str.length, chars)\n .padEnd(length, chars);\n}\n"],"mappings":"AAmCA,SAAgB,
|
|
1
|
+
{"version":3,"file":"pad.mjs","names":[],"sources":["../src/pad.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.\n * If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.\n *\n * @param str - The string to pad.\n * @param length - The length of the resulting string once padded.\n * @param chars - The character(s) to use for padding.\n * @returns The padded string, or the original string if padding is not required.\n *\n * @example\n * ```ts\n * const result1 = pad('abc', 8); // result will be ' abc '\n * const result2 = pad('abc', 8, '_-'); // result will be '_-abc_-_'\n * const result3 = pad('abc', 3); // result will be 'abc'\n * const result4 = pad('abc', 2); // result will be 'abc'\n * ```\n */\nexport function pad(str: string, length: number, chars = \" \"): string {\n return str\n .padStart(Math.floor((length - str.length) / 2) + str.length, chars)\n .padEnd(length, chars);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,SAAgB,IAAI,KAAa,QAAgB,QAAQ,KAAa;AACpE,QAAO,IACJ,SAAS,KAAK,OAAO,SAAS,IAAI,UAAU,EAAE,GAAG,IAAI,QAAQ,MAAM,CACnE,OAAO,QAAQ,MAAM"}
|
package/dist/pascal-case.cjs
CHANGED
|
@@ -1 +1,32 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_acronyms = require('./acronyms.cjs');
|
|
2
|
+
const require_get_words = require('./get-words.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/pascal-case.ts
|
|
5
|
+
/**
|
|
6
|
+
* Check if the input string is in pascal case.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - "ThisIsAnExample".
|
|
10
|
+
*
|
|
11
|
+
* @param input - The input string to check.
|
|
12
|
+
* @returns True if the input is in pascal case, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
function isPascalCase(input) {
|
|
15
|
+
return input ? /^[A-Z][A-Z0-9]*$/.test(input) && require_acronyms.ACRONYM_LIST.includes(input.trim().toUpperCase()) || /^(?:[A-Z][A-Z0-9]*[a-z]+)*$/.test(input) : false;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert the input string to pascal case.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - "ThisIsAnExample".
|
|
22
|
+
*
|
|
23
|
+
* @param input - The input string.
|
|
24
|
+
* @returns The pascal-cased string.
|
|
25
|
+
*/
|
|
26
|
+
function pascalCase(input) {
|
|
27
|
+
return isPascalCase(input) || input === void 0 ? input : require_get_words.getWords(input).map((word) => require_acronyms.ACRONYM_LIST.includes(word.trim().toUpperCase()) ? require_acronyms.ACRONYMS[word.trim().toUpperCase()]?.display || word.trim().toUpperCase() : word.trim().charAt(0).toUpperCase() + word.trim().slice(1).toLowerCase()).join("");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.isPascalCase = isPascalCase;
|
|
32
|
+
exports.pascalCase = pascalCase;
|
package/dist/pascal-case.mjs
CHANGED
|
@@ -1,2 +1,32 @@
|
|
|
1
|
-
import{ACRONYMS
|
|
1
|
+
import { ACRONYMS, ACRONYM_LIST } from "./acronyms.mjs";
|
|
2
|
+
import { getWords } from "./get-words.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/pascal-case.ts
|
|
5
|
+
/**
|
|
6
|
+
* Check if the input string is in pascal case.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - "ThisIsAnExample".
|
|
10
|
+
*
|
|
11
|
+
* @param input - The input string to check.
|
|
12
|
+
* @returns True if the input is in pascal case, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
function isPascalCase(input) {
|
|
15
|
+
return input ? /^[A-Z][A-Z0-9]*$/.test(input) && ACRONYM_LIST.includes(input.trim().toUpperCase()) || /^(?:[A-Z][A-Z0-9]*[a-z]+)*$/.test(input) : false;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert the input string to pascal case.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - "ThisIsAnExample".
|
|
22
|
+
*
|
|
23
|
+
* @param input - The input string.
|
|
24
|
+
* @returns The pascal-cased string.
|
|
25
|
+
*/
|
|
26
|
+
function pascalCase(input) {
|
|
27
|
+
return isPascalCase(input) || input === void 0 ? input : getWords(input).map((word) => ACRONYM_LIST.includes(word.trim().toUpperCase()) ? ACRONYMS[word.trim().toUpperCase()]?.display || word.trim().toUpperCase() : word.trim().charAt(0).toUpperCase() + word.trim().slice(1).toLowerCase()).join("");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { isPascalCase, pascalCase };
|
|
2
32
|
//# sourceMappingURL=pascal-case.mjs.map
|
package/dist/pascal-case.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pascal-case.mjs","names":[],"sources":["../src/pascal-case.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { ACRONYM_LIST, ACRONYMS } from \"./acronyms\";\nimport { getWords } from \"./get-words\";\n\n/**\n * Check if the input string is in pascal case.\n *\n * @remarks\n * Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - \"ThisIsAnExample\".\n *\n * @param input - The input string to check.\n * @returns True if the input is in pascal case, false otherwise.\n */\nexport function isPascalCase(input: string | undefined): boolean {\n return input\n ? (/^[A-Z][A-Z0-9]*$/.test(input) &&\n ACRONYM_LIST.includes(input.trim().toUpperCase())) ||\n /^(?:[A-Z][A-Z0-9]*[a-z]+)*$/.test(input)\n : false;\n}\n\n/**\n * Convert the input string to pascal case.\n *\n * @remarks\n * Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - \"ThisIsAnExample\".\n *\n * @param input - The input string.\n * @returns The pascal-cased string.\n */\nexport function pascalCase<T extends string | undefined>(input?: T): T {\n return (\n isPascalCase(input) || input === undefined\n ? input\n : getWords(input)\n .map(word =>\n ACRONYM_LIST.includes(word.trim().toUpperCase())\n ? ACRONYMS[word.trim().toUpperCase()]?.display ||\n word.trim().toUpperCase()\n : word.trim().charAt(0).toUpperCase() +\n word.trim().slice(1).toLowerCase()\n )\n .join(\"\")\n ) as T;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pascal-case.mjs","names":[],"sources":["../src/pascal-case.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { ACRONYM_LIST, ACRONYMS } from \"./acronyms\";\nimport { getWords } from \"./get-words\";\n\n/**\n * Check if the input string is in pascal case.\n *\n * @remarks\n * Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - \"ThisIsAnExample\".\n *\n * @param input - The input string to check.\n * @returns True if the input is in pascal case, false otherwise.\n */\nexport function isPascalCase(input: string | undefined): boolean {\n return input\n ? (/^[A-Z][A-Z0-9]*$/.test(input) &&\n ACRONYM_LIST.includes(input.trim().toUpperCase())) ||\n /^(?:[A-Z][A-Z0-9]*[a-z]+)*$/.test(input)\n : false;\n}\n\n/**\n * Convert the input string to pascal case.\n *\n * @remarks\n * Pascal case is defined as an uppercase first letter followed by any number of lowercase letters and digits - \"ThisIsAnExample\".\n *\n * @param input - The input string.\n * @returns The pascal-cased string.\n */\nexport function pascalCase<T extends string | undefined>(input?: T): T {\n return (\n isPascalCase(input) || input === undefined\n ? input\n : getWords(input)\n .map(word =>\n ACRONYM_LIST.includes(word.trim().toUpperCase())\n ? ACRONYMS[word.trim().toUpperCase()]?.display ||\n word.trim().toUpperCase()\n : word.trim().charAt(0).toUpperCase() +\n word.trim().slice(1).toLowerCase()\n )\n .join(\"\")\n ) as T;\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgB,aAAa,OAAoC;AAC/D,QAAO,QACF,mBAAmB,KAAK,MAAM,IAC7B,aAAa,SAAS,MAAM,MAAM,CAAC,aAAa,CAAC,IACjD,8BAA8B,KAAK,MAAM,GAC3C;;;;;;;;;;;AAYN,SAAgB,WAAyC,OAAc;AACrE,QACE,aAAa,MAAM,IAAI,UAAU,SAC7B,QACA,SAAS,MAAM,CACZ,KAAI,SACH,aAAa,SAAS,KAAK,MAAM,CAAC,aAAa,CAAC,GAC5C,SAAS,KAAK,MAAM,CAAC,aAAa,GAAG,WACrC,KAAK,MAAM,CAAC,aAAa,GACzB,KAAK,MAAM,CAAC,OAAO,EAAE,CAAC,aAAa,GACnC,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,aAAa,CACvC,CACA,KAAK,GAAG"}
|
package/dist/period-split.cjs
CHANGED
|
@@ -1 +1,38 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_base = require('./types/src/base.cjs');
|
|
2
|
+
const require_upper_case_first = require('./upper-case-first.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/period-split.ts
|
|
5
|
+
/**
|
|
6
|
+
* Check if the input string is in snake case.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Snake case is defined as all lowercase letters with underscores separating words - "this_is_an_example"
|
|
10
|
+
*
|
|
11
|
+
* @param input - The input string to check.
|
|
12
|
+
* @returns True if the input is in snake case, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
function isPeriodSplit(input) {
|
|
15
|
+
return input ? /^[a-z]+(?:\.[a-z0-9]+)*$/.test(input) : false;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Make all characters lowercase and add a period in between each word
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* "this.is.an.example"
|
|
22
|
+
*
|
|
23
|
+
* @param input - The input string.
|
|
24
|
+
* @returns The period-split string.
|
|
25
|
+
*/
|
|
26
|
+
function periodSplit(input) {
|
|
27
|
+
if (!input || isPeriodSplit(input)) return input;
|
|
28
|
+
const parts = input?.replace(/[A-Z]+/g, (input$1) => require_upper_case_first.upperCaseFirst(input$1) ?? require_base.EMPTY_STRING)?.split(/(?=[A-Z])|[\s._-]/).map((x) => x.toLowerCase()) ?? [];
|
|
29
|
+
if (parts.length === 0) return "";
|
|
30
|
+
if (parts.length === 1) return parts[0];
|
|
31
|
+
return parts.reduce((ret, part) => {
|
|
32
|
+
return `${ret}.${part.toLowerCase()}`.toLowerCase();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.isPeriodSplit = isPeriodSplit;
|
|
38
|
+
exports.periodSplit = periodSplit;
|