@stryke/string-format 0.1.3
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/LICENSE +201 -0
- package/README.md +295 -0
- package/dist/acronyms.cjs +7 -0
- package/dist/acronyms.d.ts +1 -0
- package/dist/acronyms.mjs +1 -0
- package/dist/camel-case.cjs +10 -0
- package/dist/camel-case.d.ts +10 -0
- package/dist/camel-case.mjs +1 -0
- package/dist/constant-case.cjs +9 -0
- package/dist/constant-case.d.ts +10 -0
- package/dist/constant-case.mjs +1 -0
- package/dist/deburr.cjs +10 -0
- package/dist/deburr.d.ts +20 -0
- package/dist/deburr.mjs +1 -0
- package/dist/escape.cjs +16 -0
- package/dist/escape.d.ts +17 -0
- package/dist/escape.mjs +1 -0
- package/dist/get-words.cjs +12 -0
- package/dist/get-words.d.ts +28 -0
- package/dist/get-words.mjs +1 -0
- package/dist/index.cjs +214 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.mjs +1 -0
- package/dist/kebab-case.cjs +13 -0
- package/dist/kebab-case.d.ts +10 -0
- package/dist/kebab-case.mjs +1 -0
- package/dist/lower-case-first.cjs +8 -0
- package/dist/lower-case-first.d.ts +10 -0
- package/dist/lower-case-first.mjs +1 -0
- package/dist/normalize-email.cjs +19 -0
- package/dist/normalize-email.d.ts +16 -0
- package/dist/normalize-email.mjs +1 -0
- package/dist/pad.cjs +9 -0
- package/dist/pad.d.ts +18 -0
- package/dist/pad.mjs +1 -0
- package/dist/pascal-case.cjs +8 -0
- package/dist/pascal-case.d.ts +10 -0
- package/dist/pascal-case.mjs +1 -0
- package/dist/period-split.cjs +13 -0
- package/dist/period-split.d.ts +10 -0
- package/dist/period-split.mjs +1 -0
- package/dist/pretty-bytes.cjs +48 -0
- package/dist/pretty-bytes.d.ts +148 -0
- package/dist/pretty-bytes.mjs +1 -0
- package/dist/snake-case.cjs +17 -0
- package/dist/snake-case.d.ts +14 -0
- package/dist/snake-case.mjs +1 -0
- package/dist/start-case.cjs +13 -0
- package/dist/start-case.d.ts +20 -0
- package/dist/start-case.mjs +1 -0
- package/dist/strip-indents.cjs +11 -0
- package/dist/strip-indents.d.ts +17 -0
- package/dist/strip-indents.mjs +3 -0
- package/dist/title-case.cjs +10 -0
- package/dist/title-case.d.ts +10 -0
- package/dist/title-case.mjs +1 -0
- package/dist/unescape.cjs +16 -0
- package/dist/unescape.d.ts +16 -0
- package/dist/unescape.mjs +1 -0
- package/dist/upper-case-first.cjs +8 -0
- package/dist/upper-case-first.d.ts +10 -0
- package/dist/upper-case-first.mjs +1 -0
- package/package.json +337 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regular expression pattern to split strings into words for various case conversions
|
|
3
|
+
*
|
|
4
|
+
* This pattern matches sequences of characters in a string, considering the following case:
|
|
5
|
+
* - Sequences of two or more uppercase letters followed by an uppercase letter and lowercase letters or digits (for acronyms)
|
|
6
|
+
* - Sequences of one uppercase letter optionally followed by lowercase letters and digits
|
|
7
|
+
* - Single uppercase letters
|
|
8
|
+
* - Sequences of digits
|
|
9
|
+
*
|
|
10
|
+
* The resulting match can be used to convert camelCase, snake_case, kebab-case, and other mixed formats into
|
|
11
|
+
* a consistent format like snake case.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const matches = 'camelCaseHTTPRequest'.match(CASE_SPLIT_PATTERN);
|
|
15
|
+
* // matches: ['camel', 'Case', 'HTTP', 'Request']
|
|
16
|
+
*/
|
|
17
|
+
export declare const CASE_SPLIT_PATTERN: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* Splits a string into words using a regular expression pattern
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const words = getWords('camelCaseHTTPRequest');
|
|
23
|
+
* // words: ['camel', 'Case', 'HTTP', 'Request']
|
|
24
|
+
*
|
|
25
|
+
* @param str - The string to split into words
|
|
26
|
+
* @returns An array of words
|
|
27
|
+
*/
|
|
28
|
+
export declare function getWords(str: string): string[];
|
|
@@ -0,0 +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)??[]]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _acronyms = require("./acronyms.cjs");
|
|
7
|
+
Object.keys(_acronyms).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _acronyms[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _acronyms[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _camelCase = require("./camel-case.cjs");
|
|
18
|
+
Object.keys(_camelCase).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _camelCase[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _camelCase[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _constantCase = require("./constant-case.cjs");
|
|
29
|
+
Object.keys(_constantCase).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _constantCase[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _constantCase[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _deburr = require("./deburr.cjs");
|
|
40
|
+
Object.keys(_deburr).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _deburr[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _deburr[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _escape = require("./escape.cjs");
|
|
51
|
+
Object.keys(_escape).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _escape[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _escape[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var _getWords = require("./get-words.cjs");
|
|
62
|
+
Object.keys(_getWords).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _getWords[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _getWords[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var _kebabCase = require("./kebab-case.cjs");
|
|
73
|
+
Object.keys(_kebabCase).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _kebabCase[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _kebabCase[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
var _lowerCaseFirst = require("./lower-case-first.cjs");
|
|
84
|
+
Object.keys(_lowerCaseFirst).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _lowerCaseFirst[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _lowerCaseFirst[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
var _normalizeEmail = require("./normalize-email.cjs");
|
|
95
|
+
Object.keys(_normalizeEmail).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _normalizeEmail[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return _normalizeEmail[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
var _pad = require("./pad.cjs");
|
|
106
|
+
Object.keys(_pad).forEach(function (key) {
|
|
107
|
+
if (key === "default" || key === "__esModule") return;
|
|
108
|
+
if (key in exports && exports[key] === _pad[key]) return;
|
|
109
|
+
Object.defineProperty(exports, key, {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return _pad[key];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
var _pascalCase = require("./pascal-case.cjs");
|
|
117
|
+
Object.keys(_pascalCase).forEach(function (key) {
|
|
118
|
+
if (key === "default" || key === "__esModule") return;
|
|
119
|
+
if (key in exports && exports[key] === _pascalCase[key]) return;
|
|
120
|
+
Object.defineProperty(exports, key, {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return _pascalCase[key];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
var _periodSplit = require("./period-split.cjs");
|
|
128
|
+
Object.keys(_periodSplit).forEach(function (key) {
|
|
129
|
+
if (key === "default" || key === "__esModule") return;
|
|
130
|
+
if (key in exports && exports[key] === _periodSplit[key]) return;
|
|
131
|
+
Object.defineProperty(exports, key, {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function () {
|
|
134
|
+
return _periodSplit[key];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
var _prettyBytes = require("./pretty-bytes.cjs");
|
|
139
|
+
Object.keys(_prettyBytes).forEach(function (key) {
|
|
140
|
+
if (key === "default" || key === "__esModule") return;
|
|
141
|
+
if (key in exports && exports[key] === _prettyBytes[key]) return;
|
|
142
|
+
Object.defineProperty(exports, key, {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function () {
|
|
145
|
+
return _prettyBytes[key];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
var _snakeCase = require("./snake-case.cjs");
|
|
150
|
+
Object.keys(_snakeCase).forEach(function (key) {
|
|
151
|
+
if (key === "default" || key === "__esModule") return;
|
|
152
|
+
if (key in exports && exports[key] === _snakeCase[key]) return;
|
|
153
|
+
Object.defineProperty(exports, key, {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function () {
|
|
156
|
+
return _snakeCase[key];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
var _startCase = require("./start-case.cjs");
|
|
161
|
+
Object.keys(_startCase).forEach(function (key) {
|
|
162
|
+
if (key === "default" || key === "__esModule") return;
|
|
163
|
+
if (key in exports && exports[key] === _startCase[key]) return;
|
|
164
|
+
Object.defineProperty(exports, key, {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
get: function () {
|
|
167
|
+
return _startCase[key];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
var _stripIndents = require("./strip-indents.cjs");
|
|
172
|
+
Object.keys(_stripIndents).forEach(function (key) {
|
|
173
|
+
if (key === "default" || key === "__esModule") return;
|
|
174
|
+
if (key in exports && exports[key] === _stripIndents[key]) return;
|
|
175
|
+
Object.defineProperty(exports, key, {
|
|
176
|
+
enumerable: true,
|
|
177
|
+
get: function () {
|
|
178
|
+
return _stripIndents[key];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
var _titleCase = require("./title-case.cjs");
|
|
183
|
+
Object.keys(_titleCase).forEach(function (key) {
|
|
184
|
+
if (key === "default" || key === "__esModule") return;
|
|
185
|
+
if (key in exports && exports[key] === _titleCase[key]) return;
|
|
186
|
+
Object.defineProperty(exports, key, {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function () {
|
|
189
|
+
return _titleCase[key];
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
var _unescape = require("./unescape.cjs");
|
|
194
|
+
Object.keys(_unescape).forEach(function (key) {
|
|
195
|
+
if (key === "default" || key === "__esModule") return;
|
|
196
|
+
if (key in exports && exports[key] === _unescape[key]) return;
|
|
197
|
+
Object.defineProperty(exports, key, {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
get: function () {
|
|
200
|
+
return _unescape[key];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
var _upperCaseFirst = require("./upper-case-first.cjs");
|
|
205
|
+
Object.keys(_upperCaseFirst).forEach(function (key) {
|
|
206
|
+
if (key === "default" || key === "__esModule") return;
|
|
207
|
+
if (key in exports && exports[key] === _upperCaseFirst[key]) return;
|
|
208
|
+
Object.defineProperty(exports, key, {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
get: function () {
|
|
211
|
+
return _upperCaseFirst[key];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The string-format library used by Storm Software for building TypeScript applications.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* A collection of helper functions used to manipulate string values
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export * from "./acronyms";
|
|
10
|
+
export * from "./camel-case";
|
|
11
|
+
export * from "./constant-case";
|
|
12
|
+
export * from "./deburr";
|
|
13
|
+
export * from "./escape";
|
|
14
|
+
export * from "./get-words";
|
|
15
|
+
export * from "./kebab-case";
|
|
16
|
+
export * from "./lower-case-first";
|
|
17
|
+
export * from "./normalize-email";
|
|
18
|
+
export * from "./pad";
|
|
19
|
+
export * from "./pascal-case";
|
|
20
|
+
export * from "./period-split";
|
|
21
|
+
export * from "./pretty-bytes";
|
|
22
|
+
export * from "./snake-case";
|
|
23
|
+
export * from "./start-case";
|
|
24
|
+
export * from "./strip-indents";
|
|
25
|
+
export * from "./title-case";
|
|
26
|
+
export * from "./unescape";
|
|
27
|
+
export * from "./upper-case-first";
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./acronyms";export*from"./camel-case";export*from"./constant-case";export*from"./deburr";export*from"./escape";export*from"./get-words";export*from"./kebab-case";export*from"./lower-case-first";export*from"./normalize-email";export*from"./pad";export*from"./pascal-case";export*from"./period-split";export*from"./pretty-bytes";export*from"./snake-case";export*from"./start-case";export*from"./strip-indents";export*from"./title-case";export*from"./unescape";export*from"./upper-case-first";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.kebabCase = void 0;
|
|
7
|
+
var _types = require("@stryke/types");
|
|
8
|
+
var _upperCaseFirst = require("./upper-case-first.cjs");
|
|
9
|
+
const kebabCase = t => {
|
|
10
|
+
const e = t?.replace(/(?<temp1>[A-Z])+/g, r => (0, _upperCaseFirst.upperCaseFirst)(r) ?? _types.EMPTY_STRING)?.split(/(?=[A-Z])|[\s._-]/).map(r => r.toLowerCase()) ?? [];
|
|
11
|
+
return e.length === 0 ? "" : e.length === 1 ? e[0] : e.reduce((r, s) => `${r}-${s.toLowerCase()}`.toLowerCase());
|
|
12
|
+
};
|
|
13
|
+
exports.kebabCase = kebabCase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EMPTY_STRING as n}from"@stryke/types";import{upperCaseFirst as o}from"./upper-case-first";export const kebabCase=t=>{const e=t?.replace(/(?<temp1>[A-Z])+/g,r=>o(r)??n)?.split(/(?=[A-Z])|[\s._-]/).map(r=>r.toLowerCase())??[];return e.length===0?"":e.length===1?e[0]:e.reduce((r,s)=>`${r}-${s.toLowerCase()}`.toLowerCase())};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const lowerCaseFirst=e=>e&&e.charAt(0).toLowerCase()+e.slice(1);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.normalizeEmail = void 0;
|
|
7
|
+
const l = /\./g;
|
|
8
|
+
const normalizeEmail = e => {
|
|
9
|
+
if (!e.includes("@") && !e.includes("+")) throw new Error("invalid_email_format");
|
|
10
|
+
const o = e.split("@").filter(Boolean);
|
|
11
|
+
if (o.length > 1) throw new Error("invalid_email_format");
|
|
12
|
+
const [i, n] = o;
|
|
13
|
+
let [r] = i.split("+");
|
|
14
|
+
if (!r) throw new Error("invalid_email_format");
|
|
15
|
+
r = r.replace(l, "");
|
|
16
|
+
const t = r.toLowerCase() + "@" + n.toLowerCase();
|
|
17
|
+
return Number(t), t;
|
|
18
|
+
};
|
|
19
|
+
exports.normalizeEmail = normalizeEmail;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 1. Lower-cases whole email.
|
|
3
|
+
* 2. Removes dots ".".
|
|
4
|
+
* 3. Remotes name part after "+".
|
|
5
|
+
* 4. Throws if cannot parse the email.
|
|
6
|
+
*
|
|
7
|
+
* For example, this email
|
|
8
|
+
*
|
|
9
|
+
* Michal.Loler+twitter\@Gmail.com
|
|
10
|
+
*
|
|
11
|
+
* will be normalized to
|
|
12
|
+
*
|
|
13
|
+
* michalloler\@gmail.com
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export declare const normalizeEmail: (email: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const l=/\./g;export const normalizeEmail=e=>{if(!e.includes("@")&&!e.includes("+"))throw new Error("invalid_email_format");const o=e.split("@").filter(Boolean);if(o.length>1)throw new Error("invalid_email_format");const[i,n]=o;let[r]=i.split("+");if(!r)throw new Error("invalid_email_format");r=r.replace(l,"");const t=r.toLowerCase()+"@"+n.toLowerCase();return Number(t),t};
|
package/dist/pad.cjs
ADDED
package/dist/pad.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
3
|
+
* 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.
|
|
4
|
+
*
|
|
5
|
+
* @param str - The string to pad.
|
|
6
|
+
* @param length - The length of the resulting string once padded.
|
|
7
|
+
* @param chars - The character(s) to use for padding.
|
|
8
|
+
* @returns The padded string, or the original string if padding is not required.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const result1 = pad('abc', 8); // result will be ' abc '
|
|
13
|
+
* const result2 = pad('abc', 8, '_-'); // result will be '_-abc_-_'
|
|
14
|
+
* const result3 = pad('abc', 3); // result will be 'abc'
|
|
15
|
+
* const result4 = pad('abc', 2); // result will be 'abc'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function pad(str: string, length: number, chars?: string): string;
|
package/dist/pad.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function pad(n,t,r=" "){return n.padStart(Math.floor((t-n.length)/2)+n.length,r).padEnd(t,r)}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.pascalCase = void 0;
|
|
7
|
+
const pascalCase = e => e && e.split(" ").map(r => r.length > 0 ? r.trim().charAt(0).toUpperCase() + r.trim().slice(1) : "").join("");
|
|
8
|
+
exports.pascalCase = pascalCase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const pascalCase=e=>e&&e.split(" ").map(r=>r.length>0?r.trim().charAt(0).toUpperCase()+r.trim().slice(1):"").join("");
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.periodSplit = void 0;
|
|
7
|
+
var _types = require("@stryke/types");
|
|
8
|
+
var _upperCaseFirst = require("./upper-case-first.cjs");
|
|
9
|
+
const periodSplit = e => {
|
|
10
|
+
const t = e?.replace(/(?<temp1>[A-Z])+/g, r => (0, _upperCaseFirst.upperCaseFirst)(r) ?? _types.EMPTY_STRING)?.split(/(?=[A-Z])|[\s._-]/).map(r => r.toLowerCase()) ?? [];
|
|
11
|
+
return t.length === 0 ? "" : t.length === 1 ? t[0] : t.reduce((r, n) => `${r}.${n.toLowerCase()}`.toLowerCase());
|
|
12
|
+
};
|
|
13
|
+
exports.periodSplit = periodSplit;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make all characters lowercase and add a period in between each word
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* "this.is.an.example"
|
|
6
|
+
*
|
|
7
|
+
* @param input - The input string.
|
|
8
|
+
* @returns The period-split string.
|
|
9
|
+
*/
|
|
10
|
+
export declare const periodSplit: (input?: string) => string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EMPTY_STRING as s}from"@stryke/types";import{upperCaseFirst as i}from"./upper-case-first";export const periodSplit=e=>{const t=e?.replace(/(?<temp1>[A-Z])+/g,r=>i(r)??s)?.split(/(?=[A-Z])|[\s._-]/).map(r=>r.toLowerCase())??[];return t.length===0?"":t.length===1?t[0]:t.reduce((r,n)=>`${r}.${n.toLowerCase()}`.toLowerCase())};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.prettyBytes = prettyBytes;
|
|
7
|
+
exports.toLocaleString = void 0;
|
|
8
|
+
const u = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
|
|
9
|
+
B = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"],
|
|
10
|
+
f = ["b", "kbit", "Mbit", "Gbit", "Tbit", "Pbit", "Ebit", "Zbit", "Ybit"],
|
|
11
|
+
y = ["b", "kibit", "Mibit", "Gibit", "Tibit", "Pibit", "Eibit", "Zibit", "Yibit"];
|
|
12
|
+
const toLocaleString = (r, o, i = {}) => {
|
|
13
|
+
let t = r,
|
|
14
|
+
n = o;
|
|
15
|
+
return typeof n == "string" ? (n || (n = process.env.STORM_LOCALE || "en-US"), Array.isArray(n) && (t = r?.toLocaleString(n, i))) : (n === !0 || i !== void 0) && (t = r?.toLocaleString(void 0, i)), String(t);
|
|
16
|
+
};
|
|
17
|
+
exports.toLocaleString = toLocaleString;
|
|
18
|
+
function prettyBytes(r, o) {
|
|
19
|
+
let i = r;
|
|
20
|
+
if (!Number.isFinite(i)) throw new TypeError(`Expected a finite number, got ${typeof i}: ${i}`);
|
|
21
|
+
const t = {
|
|
22
|
+
bits: !1,
|
|
23
|
+
binary: !1,
|
|
24
|
+
space: !0,
|
|
25
|
+
...o
|
|
26
|
+
},
|
|
27
|
+
n = t.bits ? t.binary ? y : f : t.binary ? B : u,
|
|
28
|
+
a = t.space ? " " : "";
|
|
29
|
+
if (t.signed && i === 0) return ` 0${a}${n[0]}`;
|
|
30
|
+
const s = i < 0,
|
|
31
|
+
b = s ? "-" : t.signed ? "+" : "";
|
|
32
|
+
s && (i = -i);
|
|
33
|
+
let e;
|
|
34
|
+
if (t.minimumFractionDigits !== void 0 && (e = {
|
|
35
|
+
minimumFractionDigits: t.minimumFractionDigits
|
|
36
|
+
}), t.maximumFractionDigits !== void 0 && (e = {
|
|
37
|
+
maximumFractionDigits: t.maximumFractionDigits,
|
|
38
|
+
...e
|
|
39
|
+
}), i < 1) {
|
|
40
|
+
const g = toLocaleString(i, t.locale, e);
|
|
41
|
+
return b + g + a + n[0];
|
|
42
|
+
}
|
|
43
|
+
const l = Math.min(Math.floor(t.binary ? Math.log(i) / Math.log(1024) : Math.log10(i) / 3), n.length - 1);
|
|
44
|
+
i /= (t.binary ? 1024 : 1e3) ** l, e || (i = i.toPrecision(3));
|
|
45
|
+
const c = toLocaleString(Number(i), t.locale, e),
|
|
46
|
+
m = n[l];
|
|
47
|
+
return b + c + a + m;
|
|
48
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/**
|
|
3
|
+
* Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.
|
|
4
|
+
*
|
|
5
|
+
* @defaultValue false
|
|
6
|
+
* */
|
|
7
|
+
readonly signed?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* - If `false`: Output won't be localized.
|
|
10
|
+
* - If `true`: Localize the output using the system/browser locale.
|
|
11
|
+
* - If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
|
|
12
|
+
* - If `string[]`: Expects a list of [BCP 47 language tags](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
|
|
13
|
+
*
|
|
14
|
+
* @defaultValue false
|
|
15
|
+
*/
|
|
16
|
+
readonly locale?: boolean | string | readonly string[];
|
|
17
|
+
/**
|
|
18
|
+
* Format the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate).
|
|
19
|
+
*
|
|
20
|
+
* @defaultValue false
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { prettyBytes } from '@stryke/string-fns/pretty-bytes';
|
|
25
|
+
*
|
|
26
|
+
* prettyBytes(1337, {bits: true});
|
|
27
|
+
* //=> '1.34 kbit'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
readonly bits?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Format the number using the [Binary Prefix](https://en.wikipedia.org/wiki/Binary_prefix) instead of the [SI Prefix](https://en.wikipedia.org/wiki/SI_prefix). This can be useful for presenting memory amounts. However, this should not be used for presenting file sizes.
|
|
33
|
+
*
|
|
34
|
+
* @defaultValue false
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { prettyBytes } from '@stryke/string-fns/pretty-bytes';
|
|
39
|
+
*
|
|
40
|
+
* prettyBytes(1000, {binary: true});
|
|
41
|
+
* //=> '1000 bit'
|
|
42
|
+
*
|
|
43
|
+
* prettyBytes(1024, {binary: true});
|
|
44
|
+
* //=> '1 kiB'
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
readonly binary?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* The minimum number of fraction digits to display.
|
|
50
|
+
*
|
|
51
|
+
* If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
|
|
52
|
+
*
|
|
53
|
+
* @defaultValue undefined
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { prettyBytes } from '@stryke/string-fns/pretty-bytes';
|
|
58
|
+
*
|
|
59
|
+
* // Show the number with at least 3 fractional digits
|
|
60
|
+
* prettyBytes(1900, {minimumFractionDigits: 3});
|
|
61
|
+
* //=> '1.900 kB'
|
|
62
|
+
*
|
|
63
|
+
* prettyBytes(1900);
|
|
64
|
+
* //=> '1.9 kB'
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
readonly minimumFractionDigits?: number;
|
|
68
|
+
/**
|
|
69
|
+
* The maximum number of fraction digits to display.
|
|
70
|
+
*
|
|
71
|
+
* If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
|
|
72
|
+
*
|
|
73
|
+
* @defaultValue undefined
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { prettyBytes } from '@stryke/string-fns/pretty-bytes';
|
|
78
|
+
*
|
|
79
|
+
* // Show the number with at most 1 fractional digit
|
|
80
|
+
* prettyBytes(1920, {maximumFractionDigits: 1});
|
|
81
|
+
* //=> '1.9 kB'
|
|
82
|
+
*
|
|
83
|
+
* prettyBytes(1920);
|
|
84
|
+
* //=> '1.92 kB'
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
readonly maximumFractionDigits?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Put a space between the number and unit.
|
|
90
|
+
*
|
|
91
|
+
* @defaultValue true
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { prettyBytes } from '@stryke/string-fns/pretty-bytes';
|
|
96
|
+
*
|
|
97
|
+
* prettyBytes(1920, {space: false});
|
|
98
|
+
* //=> '1.9kB'
|
|
99
|
+
*
|
|
100
|
+
* prettyBytes(1920);
|
|
101
|
+
* //=> '1.92 kB'
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
readonly space?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Formats the given number using `Number#toLocaleString`.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* - If locale is a string, the value is expected to be a locale-key (for example: `de`).
|
|
111
|
+
* - If locale is true, the system default locale is used for translation.
|
|
112
|
+
* - If no value for locale is specified, the number is returned unmodified.
|
|
113
|
+
*
|
|
114
|
+
* @param number - The number to format.
|
|
115
|
+
* @param locale - The locale to use for formatting the number.
|
|
116
|
+
* @param options - The options to use for formatting the number.
|
|
117
|
+
* @returns The formatted number.
|
|
118
|
+
*/
|
|
119
|
+
export declare const toLocaleString: (number?: number | string, locale?: string | readonly string[] | boolean, options?: Options) => string;
|
|
120
|
+
/**
|
|
121
|
+
* Convert bytes to a human readable string: `1337` → `1.34 kB`.
|
|
122
|
+
*
|
|
123
|
+
* @param number - The number to format.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { prettyBytes } from '@stryke/string-fns/pretty-bytes';
|
|
128
|
+
*
|
|
129
|
+
* prettyBytes(1337);
|
|
130
|
+
* //=> '1.34 kB'
|
|
131
|
+
*
|
|
132
|
+
* prettyBytes(100);
|
|
133
|
+
* //=> '100 B'
|
|
134
|
+
*
|
|
135
|
+
* // Display file size differences
|
|
136
|
+
* prettyBytes(42, {signed: true});
|
|
137
|
+
* //=> '+42 B'
|
|
138
|
+
*
|
|
139
|
+
* // Localized output using German locale
|
|
140
|
+
* prettyBytes(1337, {locale: 'de'});
|
|
141
|
+
* //=> '1,34 kB'
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @param number - The number to format.
|
|
145
|
+
* @param options - The options to use.
|
|
146
|
+
* @returns The formatted string.
|
|
147
|
+
*/
|
|
148
|
+
export declare function prettyBytes(number: number, options?: Options): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const u=["B","kB","MB","GB","TB","PB","EB","ZB","YB"],B=["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],f=["b","kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],y=["b","kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"];export const toLocaleString=(r,o,i={})=>{let t=r,n=o;return typeof n=="string"?(n||(n=process.env.STORM_LOCALE||"en-US"),Array.isArray(n)&&(t=r?.toLocaleString(n,i))):(n===!0||i!==void 0)&&(t=r?.toLocaleString(void 0,i)),String(t)};export function prettyBytes(r,o){let i=r;if(!Number.isFinite(i))throw new TypeError(`Expected a finite number, got ${typeof i}: ${i}`);const t={bits:!1,binary:!1,space:!0,...o},n=t.bits?t.binary?y:f:t.binary?B:u,a=t.space?" ":"";if(t.signed&&i===0)return` 0${a}${n[0]}`;const s=i<0,b=s?"-":t.signed?"+":"";s&&(i=-i);let e;if(t.minimumFractionDigits!==void 0&&(e={minimumFractionDigits:t.minimumFractionDigits}),t.maximumFractionDigits!==void 0&&(e={maximumFractionDigits:t.maximumFractionDigits,...e}),i<1){const g=toLocaleString(i,t.locale,e);return b+g+a+n[0]}const l=Math.min(Math.floor(t.binary?Math.log(i)/Math.log(1024):Math.log10(i)/3),n.length-1);i/=(t.binary?1024:1e3)**l,e||(i=i.toPrecision(3));const c=toLocaleString(Number(i),t.locale,e),m=n[l];return b+c+a+m}
|