@stacksjs/strings 0.64.6 → 0.67.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/src/is.ts DELETED
@@ -1,170 +0,0 @@
1
- import type { HashAlgorithm } from '@stacksjs/types'
2
- import validator from 'validator'
3
-
4
- export function isEmail(email: string) {
5
- return validator.isEmail(email)
6
- }
7
-
8
- export function isStrongPassword(password: string) {
9
- return validator.isStrongPassword(password)
10
- }
11
-
12
- export function isAlphanumeric(username: string) {
13
- return validator.isAlphanumeric(username)
14
- }
15
-
16
- export function validateUsername(username: string) {
17
- return isAlphanumeric(username)
18
- }
19
-
20
- export function isURL(url: string) {
21
- return validator.isURL(url)
22
- }
23
-
24
- export function isMobilePhone(phoneNumber: string) {
25
- return validator.isMobilePhone(phoneNumber)
26
- }
27
-
28
- export function isAlpha(name: string) {
29
- return validator.isAlpha(name)
30
- }
31
-
32
- export function isPostalCode(zipCode: string) {
33
- return validator.isPostalCode(zipCode, 'any')
34
- }
35
-
36
- export function isNumeric(number: string) {
37
- return validator.isNumeric(number)
38
- }
39
-
40
- export function isHexColor(color: string) {
41
- return validator.isHexColor(color)
42
- }
43
-
44
- export function isHexadecimal(hex: string) {
45
- return validator.isHexadecimal(hex)
46
- }
47
-
48
- export function isBase64(base64: string) {
49
- return validator.isBase64(base64)
50
- }
51
-
52
- export function isUUID(uuid: string) {
53
- return validator.isUUID(uuid)
54
- }
55
-
56
- export function isJSON(json: string) {
57
- return validator.isJSON(json)
58
- }
59
-
60
- export function isCreditCard(creditCard: string) {
61
- return validator.isCreditCard(creditCard)
62
- }
63
-
64
- export function isISBN(isbn: string) {
65
- return validator.isISBN(isbn)
66
- }
67
-
68
- export function isIP(ip: string) {
69
- return validator.isIP(ip)
70
- }
71
-
72
- export function isIPRange(ip: string) {
73
- return validator.isIPRange(ip)
74
- }
75
-
76
- export function isMACAddress(macAddress: string) {
77
- return validator.isMACAddress(macAddress)
78
- }
79
-
80
- export function isLatLong(latitude: string) {
81
- return validator.isLatLong(latitude)
82
- }
83
-
84
- export function isLatitude(longitude: string) {
85
- return validator.isLatLong(longitude)
86
- }
87
-
88
- export function isLongitude(longitude: string) {
89
- return validator.isLatLong(longitude)
90
- }
91
-
92
- export function isCurrency(currency: string) {
93
- return validator.isCurrency(currency)
94
- }
95
-
96
- export function isDataURI(dataURI: string) {
97
- return validator.isDataURI(dataURI)
98
- }
99
-
100
- export function isMimeType(mimeType: string) {
101
- return validator.isMimeType(mimeType)
102
- }
103
-
104
- export function isJWT(jwt: string) {
105
- return validator.isJWT(jwt)
106
- }
107
-
108
- export function isAscii(ascii: string) {
109
- return validator.isAscii(ascii)
110
- }
111
-
112
- export function isBase32(base32: string) {
113
- return validator.isBase32(base32)
114
- }
115
-
116
- export function isByteLength(byteLength: string) {
117
- return validator.isByteLength(byteLength)
118
- }
119
-
120
- export function isFQDN(fqdn: string) {
121
- return validator.isFQDN(fqdn)
122
- }
123
-
124
- export function isFullWidth(fullWidth: string) {
125
- return validator.isFullWidth(fullWidth)
126
- }
127
-
128
- export function isHalfWidth(halfWidth: string) {
129
- return validator.isHalfWidth(halfWidth)
130
- }
131
-
132
- export function isHash(hash: string, algorithm: HashAlgorithm) {
133
- return validator.isHash(hash, algorithm)
134
- }
135
-
136
- export function isHSL(hsl: string) {
137
- return validator.isHSL(hsl)
138
- }
139
-
140
- export function isIBAN(iban: string) {
141
- return validator.isIBAN(iban)
142
- }
143
-
144
- export function isIdentityCard(identityCard: string) {
145
- return validator.isIdentityCard(identityCard)
146
- }
147
-
148
- export function isISIN(isin: string) {
149
- return validator.isISIN(isin)
150
- }
151
-
152
- export function isISO8601(iso8601: string) {
153
- return validator.isISO8601(iso8601)
154
- }
155
-
156
- export function isISRC(isrc: string) {
157
- return validator.isISRC(isrc)
158
- }
159
-
160
- export function isISSN(issn: string) {
161
- return validator.isISSN(issn)
162
- }
163
-
164
- export function isISO31661Alpha2(iso31661Alpha2: string) {
165
- return validator.isISO31661Alpha2(iso31661Alpha2)
166
- }
167
-
168
- export function isISO31661Alpha3(iso31661Alpha3: string) {
169
- return validator.isISO31661Alpha3(iso31661Alpha3)
170
- }
package/src/macro.ts DELETED
@@ -1,131 +0,0 @@
1
- import * as c from './case'
2
- import * as p from './pluralize'
3
- import * as u from './utils'
4
-
5
- export const Str = {
6
- slash(str: string) {
7
- return u.slash(str)
8
- },
9
-
10
- ensurePrefix(prefix: string, str: string) {
11
- return u.ensurePrefix(prefix, str)
12
- },
13
-
14
- ensureSuffix(suffix: string, str: string) {
15
- return u.ensureSuffix(suffix, str)
16
- },
17
-
18
- template(str: string, ...args: any[]): string {
19
- return u.template(str, ...args)
20
- },
21
-
22
- /**
23
- * Truncate a string
24
- */
25
- truncate(str: string, length: number, end = '...') {
26
- return u.truncate(str, length, end)
27
- },
28
-
29
- random(length = 16) {
30
- return u.random(length)
31
- },
32
-
33
- capitalize(str: string) {
34
- return c.capitalize(str)
35
- },
36
-
37
- slug(str: string) {
38
- return u.slug(str)
39
- },
40
-
41
- detectIndent(str: string) {
42
- return u.detectIndent(str)
43
- },
44
-
45
- detectNewline(str: string) {
46
- return u.detectNewline(str)
47
- },
48
-
49
- camelCase(str: string) {
50
- return c.camelCase(str)
51
- },
52
-
53
- capitalCase(str: string) {
54
- return c.capitalCase(str)
55
- },
56
-
57
- constantCase(str: string) {
58
- return c.constantCase(str)
59
- },
60
-
61
- dotCase(str: string) {
62
- return c.dotCase(str)
63
- },
64
-
65
- noCase(str: string) {
66
- return c.noCase(str)
67
- },
68
-
69
- paramCase(str: string) {
70
- return c.paramCase(str)
71
- },
72
-
73
- pascalCase(str: string) {
74
- return c.pascalCase(str)
75
- },
76
-
77
- pathCase(str: string) {
78
- return c.pathCase(str)
79
- },
80
-
81
- sentenceCase(str: string) {
82
- return c.sentenceCase(str)
83
- },
84
-
85
- snakeCase(str: string) {
86
- return c.snakeCase(str)
87
- },
88
-
89
- titleCase(str: string) {
90
- return c.titleCase(str)
91
- },
92
-
93
- kebabCase(str: string) {
94
- return c.kebabCase(str)
95
- },
96
-
97
- plural(str: string) {
98
- // plural, singular, isPlural, isSingular, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule
99
- return p.plural(str)
100
- },
101
-
102
- singular(str: string) {
103
- return p.singular(str)
104
- },
105
-
106
- isPlural(str: string) {
107
- return p.isPlural(str)
108
- },
109
-
110
- isSingular(str: string) {
111
- return p.isSingular(str)
112
- },
113
-
114
- addPluralRule(rule: string | RegExp, repl: string) {
115
- return p.addPluralRule(rule, repl)
116
- },
117
-
118
- addSingularRule(rule: string | RegExp, repl: string) {
119
- return p.addSingularRule(rule, repl)
120
- },
121
-
122
- addIrregularRule(single: string, plural: string) {
123
- return p.addIrregularRule(single, plural)
124
- },
125
-
126
- addUncountableRule(word: string | RegExp) {
127
- return p.addUncountableRule(word)
128
- },
129
- }
130
-
131
- export const str = Str
package/src/pluralize.ts DELETED
@@ -1,34 +0,0 @@
1
- import * as pluralize from 'pluralize'
2
-
3
- type Rule = string | RegExp
4
- type Replacement = string
5
- type Word = string
6
- export type PluralizeTest = (word: Word) => boolean
7
-
8
- export interface Pluralize {
9
- plural: (word: Word, count?: number, inclusive?: boolean) => Word
10
- singular: (word: Word) => Word
11
- isPlural: (word: Word) => boolean
12
- isSingular: (word: Word) => boolean
13
- addPluralRule: (rule: Rule, replacement: Replacement) => void
14
- addSingularRule: (rule: Rule, replacement: Replacement) => void
15
- addIrregularRule: (single: Word, plural: Word) => void
16
- addUncountableRule: (word: Word | RegExp) => void
17
- }
18
-
19
- export const plural: Pluralize['plural'] = (word, count, inclusive) => {
20
- if (count !== undefined && inclusive) return `${count} ${pluralize.plural(word)}`
21
-
22
- return pluralize.plural(word)
23
- }
24
-
25
- export const singular: Pluralize['singular'] = (word) => pluralize.singular(word)
26
- export const isPlural: Pluralize['isPlural'] = (word) => pluralize.isPlural(word)
27
- export const isSingular: Pluralize['isSingular'] = (word) => pluralize.isSingular(word)
28
- export const addPluralRule: Pluralize['addPluralRule'] = (rule, replacement) =>
29
- pluralize.addPluralRule(rule, replacement)
30
- export const addSingularRule: Pluralize['addSingularRule'] = (rule, replacement) =>
31
- pluralize.addSingularRule(rule, replacement)
32
- export const addIrregularRule: Pluralize['addIrregularRule'] = (single, plural) =>
33
- pluralize.addIrregularRule(single, plural)
34
- export const addUncountableRule: Pluralize['addUncountableRule'] = (word) => pluralize.addUncountableRule(word)
package/src/string.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './utils'
2
- export * from './case'
3
- export * from './pluralize'
4
- export * from './macro'
5
- export * from './helpers'
package/src/types.ts DELETED
@@ -1,4 +0,0 @@
1
- declare function pluralize(word: string, count?: number, inclusive?: boolean): string
2
-
3
- export { pluralize }
4
- // export as namespace pluralize;
package/src/utils.ts DELETED
@@ -1,113 +0,0 @@
1
- import slugify from 'slugify'
2
-
3
- interface SlugOptions {
4
- replacement?: string
5
- remove?: RegExp
6
- lower?: boolean
7
- strict?: boolean
8
- locale?: string
9
- trim?: boolean
10
- }
11
-
12
- // port from nanoid
13
- // https://github.com/ai/nanoid
14
- const urlAlphabet = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
15
-
16
- /**
17
- * Replace backslash to slash
18
- *
19
- * @category String
20
- * @example
21
- * ```
22
- * slash('C:\\Users\\Chris') => 'C:/Users/Chris'
23
- * ```
24
- */
25
- export function slash(str: string) {
26
- return str.replace(/\\/g, '/')
27
- }
28
-
29
- /**
30
- * Ensure prefix of a string
31
- *
32
- * @category String
33
- * @example
34
- * ```
35
- * ensurePrefix('https://', 'google.com') => 'https://google.com'
36
- * ensurePrefix('https://', 'http://google.com') => 'https://google.com'
37
- */
38
- export function ensurePrefix(prefix: string, str: string) {
39
- if (!str.startsWith(prefix)) return prefix + str
40
- return str
41
- }
42
-
43
- /**
44
- * Ensure suffix of a string
45
- *
46
- * @category String
47
- * @example
48
- * ```
49
- * ensureSuffix('.js', 'index') => 'index.js'
50
- * ensureSuffix('.js', 'index.js') => 'index.js'
51
- * ```
52
- */
53
- export function ensureSuffix(suffix: string, str: string) {
54
- return str.endsWith(suffix) ? str : str + suffix
55
- }
56
-
57
- /**
58
- * Dead simple template engine, just like Python's `.format()`
59
- *
60
- * @category String
61
- * @example
62
- * ```
63
- * const result = template('Hello {0}! My name is {1}.',
64
- * 'Buddy',
65
- * 'Chris'
66
- * ) // Hello Buddy! My name is Chris.
67
- * ```
68
- */
69
- export function template(str: string, ...args: any[]): string {
70
- return str.replace(/{(\d+)}/g, (match, key) => {
71
- const index = Number(key)
72
-
73
- return Number.isNaN(index) ? match : args[index]
74
- })
75
- }
76
-
77
- export function truncate(str: string, length: number, end = '...') {
78
- if (str.length <= length) return str
79
-
80
- return str.slice(0, length - end.length) + end
81
- }
82
-
83
- /**
84
- * Generate a random string
85
- * @category String
86
- */
87
- export function random(size = 16, dict = urlAlphabet) {
88
- let id = ''
89
- let i = size
90
- const len = dict.length
91
- while (i--) id += dict[(Math.random() * len) | 0]
92
- return id
93
- }
94
-
95
- /**
96
- * Slugify a string
97
- * @category string
98
- * @example
99
- * ```
100
- * slug('Hello World') => 'hello-world'
101
- * ```
102
- */
103
- export function slug(str: string, options?: SlugOptions): string {
104
- if (options) return slugify(str, options)
105
-
106
- return slugify(str, {
107
- lower: true,
108
- strict: true,
109
- })
110
- }
111
-
112
- export { default as detectIndent } from 'detect-indent'
113
- export { detectNewline } from 'detect-newline'