@stacksjs/strings 0.51.0 → 0.52.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
@@ -18,19 +18,20 @@ Now, you can use it in your project:
18
18
  ```js
19
19
  import {
20
20
  // pluralize
21
+ isPlural, isSingular, singular, plural,
21
22
  addIrregularRule, addPluralRule, addSingularRule, addUncountableRule,
22
23
 
23
24
  // case
24
- camelCase, capitalCase, constantCase, dotCase,
25
- headerCase, isPlural, isSingular, kebabCase, noCase, paramCase, pascalCase,
26
- pathCase, plural, sentenceCase, singular, snakeCase,
25
+ camelCase, capitalCase, constantCase, dotCase
26
+ headerCase, kebabCase, noCase, paramCase, pascalCase,
27
+ pathCase, sentenceCase , snakeCase, titleCase
27
28
 
28
29
  // validation
29
30
  isEmail, isStrongPassword, isAlphanumeric, validateUsername, isURL, isMobilePhone, isAlpha, isPostalCode, isDate, isNumeric, isBoolean, isHexColor, isHexadecimal, isBase64, isUUID, isJSON, isCreditCard, isISBN, isIP, isIPRange, isMACAddress, isLatLong, isLatitude, isLongitude, isCurrency, isDataURI, isMimeType, isJWT, isMongoId, isAscii, isBase32, isByteLength, isFQDN, isFullWidth, isHalfWidth, isHash, isHSL, isIBAN, isIdentityCard, isISIN, isISO8601, isISRC, isISSN, isISO31661Alpha2, isISO31661Alpha3
30
31
  } from '@stacksjs/strings'
31
32
 
32
- console.log(camelCase('hello world')) // helloWorld
33
- console.log(plural('dog')) // dogs
33
+ console.log(camelCase('hello world')) //=> "helloWorld"
34
+ console.log(plural('dog')) //=> "dogs"
34
35
  ```
35
36
 
36
37
  To view the full documentation, please visit [https://stacksjs.dev/strings](https://stacksjs.dev/strings).
@@ -45,7 +46,7 @@ pnpm test
45
46
 
46
47
  Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
47
48
 
48
- ## 💪🏼 Contributing
49
+ ## 🚜 Contributing
49
50
 
50
51
  Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
51
52
 
package/dist/index.d.ts CHANGED
@@ -1,23 +1,45 @@
1
1
  export { camelCase, capitalCase, constantCase, dotCase, headerCase, paramCase as kebabCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
2
- export { addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, isPlural, isSingular, plural, singular } from 'pluralize';
2
+ export { titleCase } from 'title-case';
3
+ import pluralize from 'pluralize';
3
4
  import { HashAlgorithm } from '@stacksjs/types';
4
5
 
6
+ interface SlugOptions {
7
+ replacement?: string;
8
+ remove?: RegExp;
9
+ lower?: boolean;
10
+ strict?: boolean;
11
+ locale?: string;
12
+ trim?: boolean;
13
+ }
5
14
  /**
6
15
  * Replace backslash to slash
7
16
  *
8
17
  * @category String
18
+ * @example
19
+ * ```
20
+ * slash('C:\\Users\\Chris') => 'C:/Users/Chris'
21
+ * ```
9
22
  */
10
23
  declare function slash(str: string): string;
11
24
  /**
12
25
  * Ensure prefix of a string
13
26
  *
14
27
  * @category String
28
+ * @example
29
+ * ```
30
+ * ensurePrefix('https://', 'google.com') => 'https://google.com'
31
+ * ensurePrefix('https://', 'http://google.com') => 'https://google.com'
15
32
  */
16
33
  declare function ensurePrefix(prefix: string, str: string): string;
17
34
  /**
18
35
  * Ensure suffix of a string
19
36
  *
20
37
  * @category String
38
+ * @example
39
+ * ```
40
+ * ensureSuffix('.js', 'index') => 'index.js'
41
+ * ensureSuffix('.js', 'index.js') => 'index.js'
42
+ * ```
21
43
  */
22
44
  declare function ensureSuffix(suffix: string, str: string): string;
23
45
  /**
@@ -26,8 +48,7 @@ declare function ensureSuffix(suffix: string, str: string): string;
26
48
  * @category String
27
49
  * @example
28
50
  * ```
29
- * const result = template(
30
- * 'Hello {0}! My name is {1}.',
51
+ * const result = template('Hello {0}! My name is {1}.',
31
52
  * 'Buddy',
32
53
  * 'Chris'
33
54
  * ) // Hello Buddy! My name is Chris.
@@ -44,10 +65,28 @@ declare function randomStr(size?: number, dict?: string): string;
44
65
  * @category string
45
66
  * @example
46
67
  * ```
47
- * capitalize('hello') => 'Hello'
68
+ * capitalize('hello world') => 'Hello world'
48
69
  * ```
49
70
  */
50
71
  declare function capitalize(str: string): string;
72
+ /**
73
+ * Slugify a string
74
+ * @category string
75
+ * @example
76
+ * ```
77
+ * slug('Hello World') => 'hello-world'
78
+ * ```
79
+ */
80
+ declare function slug(str: string, options?: SlugOptions): string;
81
+
82
+ declare const plural: typeof pluralize.plural;
83
+ declare const singular: typeof pluralize.singular;
84
+ declare const isPlural: typeof pluralize.isPlural;
85
+ declare const isSingular: typeof pluralize.isSingular;
86
+ declare const addPluralRule: typeof pluralize.addPluralRule;
87
+ declare const addSingularRule: typeof pluralize.addSingularRule;
88
+ declare const addIrregularRule: typeof pluralize.addIrregularRule;
89
+ declare const addUncountableRule: typeof pluralize.addUncountableRule;
51
90
 
52
91
  declare function isEmail(email: string): boolean;
53
92
  declare function isStrongPassword(password: string): boolean;
@@ -95,4 +134,4 @@ declare function isISSN(issn: string): boolean;
95
134
  declare function isISO31661Alpha2(iso31661Alpha2: string): boolean;
96
135
  declare function isISO31661Alpha3(iso31661Alpha3: string): boolean;
97
136
 
98
- export { capitalize, ensurePrefix, ensureSuffix, isAlpha, isAlphanumeric, isAscii, isBase32, isBase64, isBoolean, isByteLength, isCreditCard, isCurrency, isDataURI, isDate, isEmail, isFQDN, isFullWidth, isHSL, isHalfWidth, isHash, isHexColor, isHexadecimal, isIBAN, isIP, isIPRange, isISBN, isISIN, isISO31661Alpha2, isISO31661Alpha3, isISO8601, isISRC, isISSN, isIdentityCard, isJSON, isJWT, isLatLong, isLatitude, isLongitude, isMACAddress, isMimeType, isMobilePhone, isMongoId, isNumeric, isPostalCode, isStrongPassword, isURL, isUUID, randomStr, slash, template, validateUsername };
137
+ export { addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, capitalize, ensurePrefix, ensureSuffix, isAlpha, isAlphanumeric, isAscii, isBase32, isBase64, isBoolean, isByteLength, isCreditCard, isCurrency, isDataURI, isDate, isEmail, isFQDN, isFullWidth, isHSL, isHalfWidth, isHash, isHexColor, isHexadecimal, isIBAN, isIP, isIPRange, isISBN, isISIN, isISO31661Alpha2, isISO31661Alpha3, isISO8601, isISRC, isISSN, isIdentityCard, isJSON, isJWT, isLatLong, isLatitude, isLongitude, isMACAddress, isMimeType, isMobilePhone, isMongoId, isNumeric, isPlural, isPostalCode, isSingular, isStrongPassword, isURL, isUUID, plural, randomStr, singular, slash, slug, template, validateUsername };
package/dist/index.mjs CHANGED
@@ -1,7 +1,10 @@
1
1
  export { camelCase, capitalCase, constantCase, dotCase, headerCase, paramCase as kebabCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
2
- export { addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, isPlural, isSingular, plural, singular } from 'pluralize';
2
+ export { titleCase } from 'title-case';
3
+ import slugify from 'slugify';
4
+ import pluralize from 'pluralize';
3
5
  import validator from 'validator';
4
6
 
7
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
5
8
  function slash(str) {
6
9
  return str.replace(/\\/g, "/");
7
10
  }
@@ -23,7 +26,6 @@ function template(str, ...args) {
23
26
  return args[index];
24
27
  });
25
28
  }
26
- const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
27
29
  function randomStr(size = 16, dict = urlAlphabet) {
28
30
  let id = "";
29
31
  let i = size;
@@ -35,6 +37,16 @@ function randomStr(size = 16, dict = urlAlphabet) {
35
37
  function capitalize(str) {
36
38
  return str[0].toUpperCase() + str.slice(1).toLowerCase();
37
39
  }
40
+ function slug(str, options) {
41
+ if (options)
42
+ return slugify(str, options);
43
+ return slugify(str, {
44
+ lower: true,
45
+ strict: true
46
+ });
47
+ }
48
+
49
+ const { plural, singular, isPlural, isSingular, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule } = pluralize;
38
50
 
39
51
  function isEmail(email) {
40
52
  return validator.isEmail(email);
@@ -172,4 +184,4 @@ function isISO31661Alpha3(iso31661Alpha3) {
172
184
  return validator.isISO31661Alpha3(iso31661Alpha3);
173
185
  }
174
186
 
175
- export { capitalize, ensurePrefix, ensureSuffix, isAlpha, isAlphanumeric, isAscii, isBase32, isBase64, isBoolean, isByteLength, isCreditCard, isCurrency, isDataURI, isDate, isEmail, isFQDN, isFullWidth, isHSL, isHalfWidth, isHash, isHexColor, isHexadecimal, isIBAN, isIP, isIPRange, isISBN, isISIN, isISO31661Alpha2, isISO31661Alpha3, isISO8601, isISRC, isISSN, isIdentityCard, isJSON, isJWT, isLatLong, isLatitude, isLongitude, isMACAddress, isMimeType, isMobilePhone, isMongoId, isNumeric, isPostalCode, isStrongPassword, isURL, isUUID, randomStr, slash, template, validateUsername };
187
+ export { addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, capitalize, ensurePrefix, ensureSuffix, isAlpha, isAlphanumeric, isAscii, isBase32, isBase64, isBoolean, isByteLength, isCreditCard, isCurrency, isDataURI, isDate, isEmail, isFQDN, isFullWidth, isHSL, isHalfWidth, isHash, isHexColor, isHexadecimal, isIBAN, isIP, isIPRange, isISBN, isISIN, isISO31661Alpha2, isISO31661Alpha3, isISO8601, isISRC, isISSN, isIdentityCard, isJSON, isJWT, isLatLong, isLatitude, isLongitude, isMACAddress, isMimeType, isMobilePhone, isMongoId, isNumeric, isPlural, isPostalCode, isSingular, isStrongPassword, isURL, isUUID, plural, randomStr, singular, slash, slug, template, validateUsername };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@stacksjs/strings",
3
3
  "type": "module",
4
- "version": "0.51.0",
5
- "packageManager": "pnpm@7.26.3",
4
+ "version": "0.52.0",
5
+ "packageManager": "pnpm@8.5.1",
6
6
  "description": "The Stacks string utilities.",
7
7
  "author": "Chris Breuer",
8
8
  "license": "MIT",
@@ -34,7 +34,12 @@
34
34
  "functions",
35
35
  "stacks"
36
36
  ],
37
- "main": "dist/index.mjs",
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/index.d.ts",
40
+ "import": "./dist/index.mjs"
41
+ }
42
+ },
38
43
  "module": "dist/index.mjs",
39
44
  "types": "dist/index.d.ts",
40
45
  "contributors": [
@@ -44,24 +49,19 @@
44
49
  "dist",
45
50
  "README.md"
46
51
  ],
47
- "engines": {
48
- "node": ">=v18.14.0",
49
- "pnpm": ">=7.26.3"
50
- },
51
52
  "peerDependencies": {
52
53
  "@types/pluralize": "^0.0.29",
53
- "@types/validator": "^13.7.11",
54
+ "@types/validator": "^13.7.17",
54
55
  "change-case": "^4.1.2",
55
56
  "pluralize": "^8.0.0",
57
+ "slugify": "^1.6.6",
58
+ "title-case": "^3.0.3",
56
59
  "validator": "^13.9.0",
57
- "@stacksjs/alias": "0.51.0",
58
- "@stacksjs/types": "0.51.0"
60
+ "@stacksjs/alias": "0.52.0",
61
+ "@stacksjs/types": "0.52.0"
59
62
  },
60
63
  "devDependencies": {
61
- "mkdist": "^1.1.0",
62
- "typescript": "^4.9.5",
63
- "unbuild": "^1.1.1",
64
- "@stacksjs/testing": "0.51.0"
64
+ "@stacksjs/development": "0.52.0"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "unbuild",
package/dist/index.cjs DELETED
@@ -1,247 +0,0 @@
1
- 'use strict';
2
-
3
- const changeCase = require('change-case');
4
- const pluralize = require('pluralize');
5
- const validator = require('validator');
6
-
7
- function slash(str) {
8
- return str.replace(/\\/g, "/");
9
- }
10
- function ensurePrefix(prefix, str) {
11
- if (!str.startsWith(prefix))
12
- return prefix + str;
13
- return str;
14
- }
15
- function ensureSuffix(suffix, str) {
16
- if (!str.endsWith(suffix))
17
- return str + suffix;
18
- return str;
19
- }
20
- function template(str, ...args) {
21
- return str.replace(/{(\d+)}/g, (match, key) => {
22
- const index = Number(key);
23
- if (Number.isNaN(index))
24
- return match;
25
- return args[index];
26
- });
27
- }
28
- const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
29
- function randomStr(size = 16, dict = urlAlphabet) {
30
- let id = "";
31
- let i = size;
32
- const len = dict.length;
33
- while (i--)
34
- id += dict[Math.random() * len | 0];
35
- return id;
36
- }
37
- function capitalize(str) {
38
- return str[0].toUpperCase() + str.slice(1).toLowerCase();
39
- }
40
-
41
- function isEmail(email) {
42
- return validator.isEmail(email);
43
- }
44
- function isStrongPassword(password) {
45
- return validator.isStrongPassword(password);
46
- }
47
- function isAlphanumeric(username) {
48
- return validator.isAlphanumeric(username);
49
- }
50
- function validateUsername(username) {
51
- return isAlphanumeric(username);
52
- }
53
- function isURL(url) {
54
- return validator.isURL(url);
55
- }
56
- function isMobilePhone(phoneNumber) {
57
- return validator.isMobilePhone(phoneNumber);
58
- }
59
- function isAlpha(name) {
60
- return validator.isAlpha(name);
61
- }
62
- function isPostalCode(zipCode) {
63
- return validator.isPostalCode(zipCode, "any");
64
- }
65
- function isDate(date) {
66
- return validator.isDate(date);
67
- }
68
- function isNumeric(number) {
69
- return validator.isNumeric(number);
70
- }
71
- function isBoolean(boolean) {
72
- return validator.isBoolean(boolean);
73
- }
74
- function isHexColor(color) {
75
- return validator.isHexColor(color);
76
- }
77
- function isHexadecimal(hex) {
78
- return validator.isHexadecimal(hex);
79
- }
80
- function isBase64(base64) {
81
- return validator.isBase64(base64);
82
- }
83
- function isUUID(uuid) {
84
- return validator.isUUID(uuid);
85
- }
86
- function isJSON(json) {
87
- return validator.isJSON(json);
88
- }
89
- function isCreditCard(creditCard) {
90
- return validator.isCreditCard(creditCard);
91
- }
92
- function isISBN(isbn) {
93
- return validator.isISBN(isbn);
94
- }
95
- function isIP(ip) {
96
- return validator.isIP(ip);
97
- }
98
- function isIPRange(ip) {
99
- return validator.isIPRange(ip);
100
- }
101
- function isMACAddress(macAddress) {
102
- return validator.isMACAddress(macAddress);
103
- }
104
- function isLatLong(latitude) {
105
- return validator.isLatLong(latitude);
106
- }
107
- function isLatitude(longitude) {
108
- return validator.isLatLong(longitude);
109
- }
110
- function isLongitude(longitude) {
111
- return validator.isLatLong(longitude);
112
- }
113
- function isCurrency(currency) {
114
- return validator.isCurrency(currency);
115
- }
116
- function isDataURI(dataURI) {
117
- return validator.isDataURI(dataURI);
118
- }
119
- function isMimeType(mimeType) {
120
- return validator.isMimeType(mimeType);
121
- }
122
- function isJWT(jwt) {
123
- return validator.isJWT(jwt);
124
- }
125
- function isMongoId(mongoId) {
126
- return validator.isMongoId(mongoId);
127
- }
128
- function isAscii(ascii) {
129
- return validator.isAscii(ascii);
130
- }
131
- function isBase32(base32) {
132
- return validator.isBase32(base32);
133
- }
134
- function isByteLength(byteLength) {
135
- return validator.isByteLength(byteLength);
136
- }
137
- function isFQDN(fqdn) {
138
- return validator.isFQDN(fqdn);
139
- }
140
- function isFullWidth(fullWidth) {
141
- return validator.isFullWidth(fullWidth);
142
- }
143
- function isHalfWidth(halfWidth) {
144
- return validator.isHalfWidth(halfWidth);
145
- }
146
- function isHash(hash, algorithm) {
147
- return validator.isHash(hash, algorithm);
148
- }
149
- function isHSL(hsl) {
150
- return validator.isHSL(hsl);
151
- }
152
- function isIBAN(iban) {
153
- return validator.isIBAN(iban);
154
- }
155
- function isIdentityCard(identityCard) {
156
- return validator.isIdentityCard(identityCard);
157
- }
158
- function isISIN(isin) {
159
- return validator.isISIN(isin);
160
- }
161
- function isISO8601(iso8601) {
162
- return validator.isISO8601(iso8601);
163
- }
164
- function isISRC(isrc) {
165
- return validator.isISRC(isrc);
166
- }
167
- function isISSN(issn) {
168
- return validator.isISSN(issn);
169
- }
170
- function isISO31661Alpha2(iso31661Alpha2) {
171
- return validator.isISO31661Alpha2(iso31661Alpha2);
172
- }
173
- function isISO31661Alpha3(iso31661Alpha3) {
174
- return validator.isISO31661Alpha3(iso31661Alpha3);
175
- }
176
-
177
- exports.camelCase = changeCase.camelCase;
178
- exports.capitalCase = changeCase.capitalCase;
179
- exports.constantCase = changeCase.constantCase;
180
- exports.dotCase = changeCase.dotCase;
181
- exports.headerCase = changeCase.headerCase;
182
- exports.kebabCase = changeCase.paramCase;
183
- exports.noCase = changeCase.noCase;
184
- exports.paramCase = changeCase.paramCase;
185
- exports.pascalCase = changeCase.pascalCase;
186
- exports.pathCase = changeCase.pathCase;
187
- exports.sentenceCase = changeCase.sentenceCase;
188
- exports.snakeCase = changeCase.snakeCase;
189
- exports.addIrregularRule = pluralize.addIrregularRule;
190
- exports.addPluralRule = pluralize.addPluralRule;
191
- exports.addSingularRule = pluralize.addSingularRule;
192
- exports.addUncountableRule = pluralize.addUncountableRule;
193
- exports.isPlural = pluralize.isPlural;
194
- exports.isSingular = pluralize.isSingular;
195
- exports.plural = pluralize.plural;
196
- exports.singular = pluralize.singular;
197
- exports.capitalize = capitalize;
198
- exports.ensurePrefix = ensurePrefix;
199
- exports.ensureSuffix = ensureSuffix;
200
- exports.isAlpha = isAlpha;
201
- exports.isAlphanumeric = isAlphanumeric;
202
- exports.isAscii = isAscii;
203
- exports.isBase32 = isBase32;
204
- exports.isBase64 = isBase64;
205
- exports.isBoolean = isBoolean;
206
- exports.isByteLength = isByteLength;
207
- exports.isCreditCard = isCreditCard;
208
- exports.isCurrency = isCurrency;
209
- exports.isDataURI = isDataURI;
210
- exports.isDate = isDate;
211
- exports.isEmail = isEmail;
212
- exports.isFQDN = isFQDN;
213
- exports.isFullWidth = isFullWidth;
214
- exports.isHSL = isHSL;
215
- exports.isHalfWidth = isHalfWidth;
216
- exports.isHash = isHash;
217
- exports.isHexColor = isHexColor;
218
- exports.isHexadecimal = isHexadecimal;
219
- exports.isIBAN = isIBAN;
220
- exports.isIP = isIP;
221
- exports.isIPRange = isIPRange;
222
- exports.isISBN = isISBN;
223
- exports.isISIN = isISIN;
224
- exports.isISO31661Alpha2 = isISO31661Alpha2;
225
- exports.isISO31661Alpha3 = isISO31661Alpha3;
226
- exports.isISO8601 = isISO8601;
227
- exports.isISRC = isISRC;
228
- exports.isISSN = isISSN;
229
- exports.isIdentityCard = isIdentityCard;
230
- exports.isJSON = isJSON;
231
- exports.isJWT = isJWT;
232
- exports.isLatLong = isLatLong;
233
- exports.isLatitude = isLatitude;
234
- exports.isLongitude = isLongitude;
235
- exports.isMACAddress = isMACAddress;
236
- exports.isMimeType = isMimeType;
237
- exports.isMobilePhone = isMobilePhone;
238
- exports.isMongoId = isMongoId;
239
- exports.isNumeric = isNumeric;
240
- exports.isPostalCode = isPostalCode;
241
- exports.isStrongPassword = isStrongPassword;
242
- exports.isURL = isURL;
243
- exports.isUUID = isUUID;
244
- exports.randomStr = randomStr;
245
- exports.slash = slash;
246
- exports.template = template;
247
- exports.validateUsername = validateUsername;