@stryke/string-format 0.4.10 â 0.5.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.
- package/README.md +1 -1
- package/dist/title-case.cjs +11 -4
- package/dist/title-case.d.ts +31 -1
- package/dist/title-case.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ This package is part of Storm Software's **đŠī¸ Stryke** monorepo. Stryke pac
|
|
|
22
22
|
|
|
23
23
|
<h3 align="center">đģ Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
|
|
24
24
|
|
|
25
|
-
[](https://prettier.io/) [](http://nx.dev/) [](https://nextjs.org/) [](http://commitizen.github.io/cz-cli/)  [](https://fumadocs.vercel.app/) 
|
|
26
26
|
|
|
27
27
|
> [!IMPORTANT] Important
|
|
28
28
|
> This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be available through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.
|
package/dist/title-case.cjs
CHANGED
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.LOWER_CASE_WHEN_NOT_FIRST = exports.FORMAT_MAPPING = void 0;
|
|
6
7
|
exports.titleCase = titleCase;
|
|
7
8
|
var _acronyms = require("./acronyms.cjs");
|
|
8
9
|
var _upperCaseFirst = require("./upper-case-first.cjs");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const FORMAT_MAPPING = exports.FORMAT_MAPPING = _acronyms.ACRONYMS.reduce((s, e) => (s[e.toLowerCase()] = e, s), {
|
|
11
|
+
cspell: "CSpell",
|
|
12
|
+
eslint: "ESLint",
|
|
13
|
+
nx: "Nx"
|
|
14
|
+
}),
|
|
15
|
+
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 titleCase(s, e = {}) {
|
|
17
|
+
if (!s) return s;
|
|
18
|
+
const n = r => r.toLowerCase().split(/[\s\-_]+/).filter(Boolean).map((t, i) => !e.skipLowerCaseWhenNotFirst && LOWER_CASE_WHEN_NOT_FIRST.includes(t.toLowerCase()) && i > 0 ? t.toLowerCase() : !e.skipFormatMapping && Object.keys(FORMAT_MAPPING).includes(t.toLowerCase()) ? FORMAT_MAPPING[t.toLowerCase()] : e.mapping && Object.keys(e.mapping).includes(t.toLowerCase()) ? e.mapping[t.toLowerCase()] : `${(0, _upperCaseFirst.upperCaseFirst)(t.toLowerCase())}`).join(" ");
|
|
19
|
+
return s.split(/\s+-\s+/).map(r => n(r)).join(" - ");
|
|
13
20
|
}
|
package/dist/title-case.d.ts
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
export declare const FORMAT_MAPPING: Record<string, string>;
|
|
2
|
+
export declare const LOWER_CASE_WHEN_NOT_FIRST: string[];
|
|
3
|
+
export interface TitleCaseOptions {
|
|
4
|
+
/**
|
|
5
|
+
* If true, skip the format mapping. This will skip the conversion of known acronyms to their upper case form.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The current list of word format mappings is stored in {@link FORMAT_MAPPING}.
|
|
9
|
+
*
|
|
10
|
+
* @defaultValue false
|
|
11
|
+
*/
|
|
12
|
+
skipFormatMapping?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* If true, lower case words that are not the first word in the title.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* The current list of words that are lower cased when not first are stored in {@link LOWER_CASE_WHEN_NOT_FIRST}.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* @defaultValue false
|
|
21
|
+
*/
|
|
22
|
+
skipLowerCaseWhenNotFirst?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* A custom mapping of words to their formatted versions.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* This allows you to provide your own mappings for specific words that should be formatted in a certain way.
|
|
28
|
+
*/
|
|
29
|
+
mapping?: Record<string, string>;
|
|
30
|
+
}
|
|
1
31
|
/**
|
|
2
32
|
* Convert the input string to title case.
|
|
3
33
|
*
|
|
@@ -7,4 +37,4 @@
|
|
|
7
37
|
* @param input - The input string.
|
|
8
38
|
* @returns The title cased string.
|
|
9
39
|
*/
|
|
10
|
-
export declare function titleCase<T extends string | undefined>(input?: T): T;
|
|
40
|
+
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 a}from"./acronyms";import{upperCaseFirst as o}from"./upper-case-first";export const FORMAT_MAPPING=a.reduce((s,e)=>(s[e.toLowerCase()]=e,s),{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 titleCase(s,e={}){if(!s)return s;const n=r=>r.toLowerCase().split(/[\s\-_]+/).filter(Boolean).map((t,i)=>!e.skipLowerCaseWhenNotFirst&&LOWER_CASE_WHEN_NOT_FIRST.includes(t.toLowerCase())&&i>0?t.toLowerCase():!e.skipFormatMapping&&Object.keys(FORMAT_MAPPING).includes(t.toLowerCase())?FORMAT_MAPPING[t.toLowerCase()]:e.mapping&&Object.keys(e.mapping).includes(t.toLowerCase())?e.mapping[t.toLowerCase()]:`${o(t.toLowerCase())}`).join(" ");return s.split(/\s+-\s+/).map(r=>n(r)).join(" - ")}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/string-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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.6.
|
|
13
|
+
"dependencies": { "@stryke/helpers": "^0.6.2", "@stryke/types": "^0.8.5" },
|
|
14
14
|
"devDependencies": {},
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"files": ["dist/**/*"],
|