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