@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 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
- [![Version](https://img.shields.io/badge/version-0.4.9-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
25
+ [![Version](https://img.shields.io/badge/version-0.4.10-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
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.
@@ -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
- function titleCase(e) {
10
- if (!e) return e;
11
- const s = t => t.toLowerCase().split(/[\s\-_]+/).filter(Boolean).map(r => _acronyms.ACRONYMS.includes(r.toUpperCase()) ? r.toUpperCase() : `${(0, _upperCaseFirst.upperCaseFirst)(r.toLowerCase())}`).join(" ");
12
- return e.split(/\s+-\s+/).map(t => s(t)).join(" - ");
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
  }
@@ -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;
@@ -1 +1 @@
1
- import{ACRONYMS as o}from"./acronyms";import{upperCaseFirst as n}from"./upper-case-first";export function titleCase(e){if(!e)return e;const s=t=>t.toLowerCase().split(/[\s\-_]+/).filter(Boolean).map(r=>o.includes(r.toUpperCase())?r.toUpperCase():`${n(r.toLowerCase())}`).join(" ");return e.split(/\s+-\s+/).map(t=>s(t)).join(" - ")}
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.4.10",
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.0", "@stryke/types": "^0.8.3" },
13
+ "dependencies": { "@stryke/helpers": "^0.6.2", "@stryke/types": "^0.8.5" },
14
14
  "devDependencies": {},
15
15
  "sideEffects": false,
16
16
  "files": ["dist/**/*"],