@stryke/string-format 0.4.11 → 0.5.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/acronyms.cjs CHANGED
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ACRONYMS = void 0;
7
- const ACRONYMS = exports.ACRONYMS = ["3D", "4D", "5G", "6G", "7G", "8G", "ACID", "AES", "AI", "AJAX", "API", "AR", "ASCII", "B2B", "B2C", "BFF", "BI", "BIOS", "BGP", "BOM", "BYOD", "C2C", "CAGR", "CAPTCHA", "CD", "CDN", "CDP", "CI", "CI/CD", "CIAM", "CICD", "CLI", "CMDB", "CORS", "CPU", "CRUD", "CSR", "CSS", "CX", "DAG", "DBMS", "DDoS", "DNS", "DNSSEC", "DOM", "DR", "DRM", "DWH", "E2E", "EAI", "EKS", "EOF", "EOD", "ETC", "ETL", "EULA", "FIDO", "FQDN", "FTP", "FaaS", "GDPR", "GCP", "GPU", "GUID", "GUI", "GZIP", "HCI", "HDD", "HDFS", "HIPAA", "HMAC", "HOTP", "HSM", "HTML", "HTTP", "HTTP/2", "HTTP/2.0", "HTTP/3", "HTTP/3.0", "HTTP2", "HTTPS", "HTTPS/2", "HTTPS/3", "HTTPS3", "IAM", "IAMM", "IAMT", "IaaS", "ID", "IMAP", "IP", "IPFS", "IoT", "JSON", "JSONP", "JWT", "K8s", "KMS", "KPI", "LAN", "LHS", "LXC", "MFA", "ML", "MLOps", "MVC", "MVP", "NAS", "NAT", "NDA", "NFS", "NIST", "NLP", "NPS", "OCR", "OEM", "OKR", "OLAP", "OLTP", "OOP", "ORM", "OS", "OTP", "P2P", "PDP", "PaaS", "PCI", "PKI", "PP", "PWA", "PX", "QA", "RAID", "RAM", "RDS", "REST", "RHS", "RPC", "RPA", "RUM", "RSS", "SAN", "SASE", "SDLC", "SDK", "SEO", "SFTP", "SIEM", "SLA", "SMB", "SMTP", "SOAP", "SOC", "SOA", "SPDY", "SPF", "SQL", "SRV", "SRE", "SSH", "SSDL", "SSO", "SSL", "SSR", "TDD", "TLD", "TLS", "TLS1.3", "TOTP", "TRPC", "TTL", "UDP", "UI", "UID", "URI", "URL", "UTF", "UUID", "UX", "VM", "VLAN", "VPN", "VR", "WAF", "WAN", "WLAN", "WPA", "XACML", "XML", "XSRF", "XSS", "XR", "YAML", "ZTA"];
7
+ const ACRONYMS = exports.ACRONYMS = ["3D", "4D", "5G", "6G", "7G", "8G", "ACID", "AES", "AI", "AJAX", "API", "AR", "ASCII", "B2B", "B2C", "BFF", "BI", "BIOS", "BGP", "BOM", "BYOD", "C2C", "CAGR", "CAPTCHA", "CD", "CDN", "CDP", "CI", "CI/CD", "CIAM", "CICD", "CLI", "CMDB", "CORS", "CPU", "CRUD", "CSR", "CSS", "CX", "DAG", "DBMS", "DDoS", "DNS", "DNSSEC", "DOM", "DR", "DRM", "DWH", "E2E", "EAI", "EKS", "EOF", "EOD", "ETC", "ETL", "EULA", "FIDO", "FQDN", "FTP", "FaaS", "GDPR", "GCP", "GPU", "GUID", "GUI", "GZIP", "HCI", "HDD", "HDFS", "HIPAA", "HMAC", "HOTP", "HSM", "HTML", "HTTP", "HTTP/2", "HTTP/2.0", "HTTP/3", "HTTP/3.0", "HTTP2", "HTTPS", "HTTPS/2", "HTTPS/3", "HTTPS3", "IAM", "IAMM", "IAMT", "IaaS", "ID", "IMAP", "IP", "IPFS", "IoT", "JSON", "JSONP", "JWT", "K8s", "KMS", "KPI", "KV", "LAN", "LHS", "LXC", "MFA", "ML", "MLOps", "MVC", "MVP", "NAS", "NAT", "NDA", "NFS", "NIST", "NLP", "NPS", "OCR", "OEM", "OKR", "OLAP", "OLTP", "OOP", "ORM", "OS", "OTP", "P2P", "PDP", "PaaS", "PCI", "PKI", "PP", "PWA", "PX", "QA", "R2", "RAID", "RAM", "RDS", "REST", "RHS", "RPC", "RPA", "RUM", "RSS", "S3", "SAN", "SASE", "SDLC", "SDK", "SEO", "SFTP", "SIEM", "SLA", "SMB", "SMTP", "SOAP", "SOC", "SOA", "SPDY", "SPF", "SQL", "SRV", "SRE", "SSH", "SSDL", "SSO", "SSL", "SSR", "TDD", "TLD", "TLS", "TLS1.3", "TOTP", "TRPC", "TTL", "UDP", "UI", "UID", "URI", "URL", "UTF", "UUID", "UX", "VM", "VLAN", "VPN", "VR", "WAF", "WAN", "WLAN", "WPA", "XACML", "XML", "XSRF", "XSS", "XR", "YAML", "ZTA"];
package/dist/acronyms.mjs CHANGED
@@ -1 +1 @@
1
- export const ACRONYMS=["3D","4D","5G","6G","7G","8G","ACID","AES","AI","AJAX","API","AR","ASCII","B2B","B2C","BFF","BI","BIOS","BGP","BOM","BYOD","C2C","CAGR","CAPTCHA","CD","CDN","CDP","CI","CI/CD","CIAM","CICD","CLI","CMDB","CORS","CPU","CRUD","CSR","CSS","CX","DAG","DBMS","DDoS","DNS","DNSSEC","DOM","DR","DRM","DWH","E2E","EAI","EKS","EOF","EOD","ETC","ETL","EULA","FIDO","FQDN","FTP","FaaS","GDPR","GCP","GPU","GUID","GUI","GZIP","HCI","HDD","HDFS","HIPAA","HMAC","HOTP","HSM","HTML","HTTP","HTTP/2","HTTP/2.0","HTTP/3","HTTP/3.0","HTTP2","HTTPS","HTTPS/2","HTTPS/3","HTTPS3","IAM","IAMM","IAMT","IaaS","ID","IMAP","IP","IPFS","IoT","JSON","JSONP","JWT","K8s","KMS","KPI","LAN","LHS","LXC","MFA","ML","MLOps","MVC","MVP","NAS","NAT","NDA","NFS","NIST","NLP","NPS","OCR","OEM","OKR","OLAP","OLTP","OOP","ORM","OS","OTP","P2P","PDP","PaaS","PCI","PKI","PP","PWA","PX","QA","RAID","RAM","RDS","REST","RHS","RPC","RPA","RUM","RSS","SAN","SASE","SDLC","SDK","SEO","SFTP","SIEM","SLA","SMB","SMTP","SOAP","SOC","SOA","SPDY","SPF","SQL","SRV","SRE","SSH","SSDL","SSO","SSL","SSR","TDD","TLD","TLS","TLS1.3","TOTP","TRPC","TTL","UDP","UI","UID","URI","URL","UTF","UUID","UX","VM","VLAN","VPN","VR","WAF","WAN","WLAN","WPA","XACML","XML","XSRF","XSS","XR","YAML","ZTA"];
1
+ export const ACRONYMS=["3D","4D","5G","6G","7G","8G","ACID","AES","AI","AJAX","API","AR","ASCII","B2B","B2C","BFF","BI","BIOS","BGP","BOM","BYOD","C2C","CAGR","CAPTCHA","CD","CDN","CDP","CI","CI/CD","CIAM","CICD","CLI","CMDB","CORS","CPU","CRUD","CSR","CSS","CX","DAG","DBMS","DDoS","DNS","DNSSEC","DOM","DR","DRM","DWH","E2E","EAI","EKS","EOF","EOD","ETC","ETL","EULA","FIDO","FQDN","FTP","FaaS","GDPR","GCP","GPU","GUID","GUI","GZIP","HCI","HDD","HDFS","HIPAA","HMAC","HOTP","HSM","HTML","HTTP","HTTP/2","HTTP/2.0","HTTP/3","HTTP/3.0","HTTP2","HTTPS","HTTPS/2","HTTPS/3","HTTPS3","IAM","IAMM","IAMT","IaaS","ID","IMAP","IP","IPFS","IoT","JSON","JSONP","JWT","K8s","KMS","KPI","KV","LAN","LHS","LXC","MFA","ML","MLOps","MVC","MVP","NAS","NAT","NDA","NFS","NIST","NLP","NPS","OCR","OEM","OKR","OLAP","OLTP","OOP","ORM","OS","OTP","P2P","PDP","PaaS","PCI","PKI","PP","PWA","PX","QA","R2","RAID","RAM","RDS","REST","RHS","RPC","RPA","RUM","RSS","S3","SAN","SASE","SDLC","SDK","SEO","SFTP","SIEM","SLA","SMB","SMTP","SOAP","SOC","SOA","SPDY","SPF","SQL","SRV","SRE","SSH","SSDL","SSO","SSL","SSR","TDD","TLD","TLS","TLS1.3","TOTP","TRPC","TTL","UDP","UI","UID","URI","URL","UTF","UUID","UX","VM","VLAN","VPN","VR","WAF","WAN","WLAN","WPA","XACML","XML","XSRF","XSS","XR","YAML","ZTA"];
@@ -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 > 1e3) throw new Error("The regular expression parameter of `get-words` can't handle strings longer than 1000 characters");
10
+ if (r.length > 2e3) 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
  }
@@ -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>1e3)throw new Error("The regular expression parameter of `get-words` can't handle strings longer than 1000 characters");return[...r.match(CASE_SPLIT_PATTERN)??[]]}
1
+ export const CASE_SPLIT_PATTERN=/[A-Z]?[a-z]+|\d+|[A-Z]+(?![a-z])/g;export function getWords(r){if(r.length>2e3)throw new Error("The regular expression parameter of `get-words` can't handle strings longer than 2000 characters");return[...r.match(CASE_SPLIT_PATTERN)??[]]}
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.kebabCase = kebabCase;
7
- var _types = require("@stryke/types");
8
- var _upperCaseFirst = require("./upper-case-first.cjs");
9
- function kebabCase(t) {
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());
7
+ var _getWords = require("./get-words.cjs");
8
+ function kebabCase(e) {
9
+ const r = e ? (0, _getWords.getWords)(e) : [];
10
+ return r.length === 0 ? "" : r.join("-").toLowerCase();
12
11
  }
@@ -1 +1 @@
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())}
1
+ import{getWords as t}from"./get-words";export function kebabCase(e){const r=e?t(e):[];return r.length===0?"":r.join("-").toLowerCase()}
@@ -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.11",
3
+ "version": "0.5.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.6.1", "@stryke/types": "^0.8.4" },
13
+ "dependencies": { "@stryke/helpers": "^0.6.2", "@stryke/types": "^0.8.5" },
14
14
  "devDependencies": {},
15
15
  "sideEffects": false,
16
16
  "files": ["dist/**/*"],
@@ -332,5 +332,6 @@
332
332
  },
333
333
  "main": "./dist/index.cjs",
334
334
  "module": "./dist/index.mjs",
335
- "types": "./dist/index.d.ts"
335
+ "types": "./dist/index.d.ts",
336
+ "gitHead": "4052d0819f6c27c02af4ccd7460b5cd28c36f5c4"
336
337
  }