@h3ravel/support 0.2.0 → 0.4.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/CHANGELOG.md +17 -0
- package/dist/index.cjs +271 -245
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -23
- package/dist/index.d.ts +23 -23
- package/dist/index.js +256 -230
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Contracts/ObjContract.ts +1 -1
- package/src/Helpers/Arr.ts +1 -1
- package/src/Helpers/Obj.ts +4 -4
- package/src/Helpers/Str.ts +1 -1
- package/tests/str.test.ts +7 -0
- package/tsconfig.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,348 +1,374 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty
|
|
2
|
-
var __name = (target, value) => __defProp(target,
|
|
1
|
+
var __defProp = Object.defineProperty
|
|
2
|
+
var __name = (target, value) => __defProp(target, 'name', { value, configurable: true })
|
|
3
3
|
|
|
4
4
|
// src/Helpers/Arr.ts
|
|
5
5
|
var chunk = /* @__PURE__ */ __name((arr, size = 2) => {
|
|
6
|
-
if (size <= 0)
|
|
7
|
-
|
|
6
|
+
if (size <= 0)
|
|
7
|
+
throw new Error('Chunk size must be greater than 0')
|
|
8
|
+
const chunks = []
|
|
8
9
|
for (let i = 0; i < arr.length; i += size) {
|
|
9
|
-
chunks.push(arr.slice(i, i + size))
|
|
10
|
+
chunks.push(arr.slice(i, i + size))
|
|
10
11
|
}
|
|
11
|
-
return chunks
|
|
12
|
-
},
|
|
12
|
+
return chunks
|
|
13
|
+
}, 'chunk')
|
|
13
14
|
var range = /* @__PURE__ */ __name((size, startAt = 0) => {
|
|
14
|
-
if (size <= 0 || !Number.isFinite(size))
|
|
15
|
+
if (size <= 0 || !Number.isFinite(size))
|
|
16
|
+
return []
|
|
15
17
|
return Array.from({
|
|
16
18
|
length: size
|
|
17
|
-
}, (_, i) => startAt + i)
|
|
18
|
-
},
|
|
19
|
+
}, (_, i) => startAt + i)
|
|
20
|
+
}, 'range')
|
|
19
21
|
|
|
20
22
|
// src/Helpers/Number.ts
|
|
21
|
-
var abbreviate = /* @__PURE__ */ __name((value, locale =
|
|
22
|
-
if (!value)
|
|
23
|
+
var abbreviate = /* @__PURE__ */ __name((value, locale = 'en-US') => {
|
|
24
|
+
if (!value)
|
|
25
|
+
return '0'
|
|
23
26
|
if (value < 1e3) {
|
|
24
|
-
return new Intl.NumberFormat(locale).format(value)
|
|
27
|
+
return new Intl.NumberFormat(locale).format(value)
|
|
25
28
|
}
|
|
26
29
|
const si = [
|
|
27
30
|
{
|
|
28
31
|
v: 1e18,
|
|
29
|
-
s:
|
|
32
|
+
s: 'E'
|
|
30
33
|
},
|
|
31
34
|
{
|
|
32
35
|
v: 1e15,
|
|
33
|
-
s:
|
|
36
|
+
s: 'P'
|
|
34
37
|
},
|
|
35
38
|
{
|
|
36
39
|
v: 1e12,
|
|
37
|
-
s:
|
|
40
|
+
s: 'T'
|
|
38
41
|
},
|
|
39
42
|
{
|
|
40
43
|
v: 1e9,
|
|
41
|
-
s:
|
|
44
|
+
s: 'B'
|
|
42
45
|
},
|
|
43
46
|
{
|
|
44
47
|
v: 1e6,
|
|
45
|
-
s:
|
|
48
|
+
s: 'M'
|
|
46
49
|
},
|
|
47
50
|
{
|
|
48
51
|
v: 1e3,
|
|
49
|
-
s:
|
|
52
|
+
s: 'K'
|
|
50
53
|
}
|
|
51
|
-
]
|
|
52
|
-
const match = si.find((scale) => value >= scale.v)
|
|
53
|
-
if (!match)
|
|
54
|
-
|
|
54
|
+
]
|
|
55
|
+
const match = si.find((scale) => value >= scale.v)
|
|
56
|
+
if (!match)
|
|
57
|
+
return new Intl.NumberFormat(locale).format(value)
|
|
58
|
+
const formatted = value / match.v
|
|
55
59
|
return new Intl.NumberFormat(locale, {
|
|
56
60
|
minimumFractionDigits: 0,
|
|
57
61
|
maximumFractionDigits: 2
|
|
58
|
-
}).format(formatted) + match.s
|
|
59
|
-
},
|
|
62
|
+
}).format(formatted) + match.s
|
|
63
|
+
}, 'abbreviate')
|
|
60
64
|
var humanize = /* @__PURE__ */ __name((num, slugify2) => {
|
|
61
65
|
if (!num) {
|
|
62
|
-
return
|
|
66
|
+
return ''
|
|
63
67
|
}
|
|
64
|
-
if (slugify2 ===
|
|
65
|
-
const h = humanize(num)
|
|
66
|
-
return typeof h ===
|
|
68
|
+
if (slugify2 === '-' || slugify2 === '_') {
|
|
69
|
+
const h = humanize(num)
|
|
70
|
+
return typeof h === 'string' ? h.replace(' ', slugify2).toLowerCase() : h
|
|
67
71
|
}
|
|
68
72
|
const ones = [
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
]
|
|
73
|
+
'',
|
|
74
|
+
'one',
|
|
75
|
+
'two',
|
|
76
|
+
'three',
|
|
77
|
+
'four',
|
|
78
|
+
'five',
|
|
79
|
+
'six',
|
|
80
|
+
'seven',
|
|
81
|
+
'eight',
|
|
82
|
+
'nine',
|
|
83
|
+
'ten',
|
|
84
|
+
'eleven',
|
|
85
|
+
'twelve',
|
|
86
|
+
'thirteen',
|
|
87
|
+
'fourteen',
|
|
88
|
+
'fifteen',
|
|
89
|
+
'sixteen',
|
|
90
|
+
'seventeen',
|
|
91
|
+
'eighteen',
|
|
92
|
+
'nineteen'
|
|
93
|
+
]
|
|
90
94
|
const tens = [
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
]
|
|
102
|
-
const numString = num.toString()
|
|
103
|
-
if (num < 0)
|
|
104
|
-
|
|
95
|
+
'',
|
|
96
|
+
'',
|
|
97
|
+
'twenty',
|
|
98
|
+
'thirty',
|
|
99
|
+
'forty',
|
|
100
|
+
'fifty',
|
|
101
|
+
'sixty',
|
|
102
|
+
'seventy',
|
|
103
|
+
'eighty',
|
|
104
|
+
'ninety'
|
|
105
|
+
]
|
|
106
|
+
const numString = num.toString()
|
|
107
|
+
if (num < 0)
|
|
108
|
+
throw new Error('Negative numbers are not supported.')
|
|
109
|
+
if (num === 0)
|
|
110
|
+
return 'zero'
|
|
105
111
|
if (num < 20) {
|
|
106
|
-
return ones[num] ??
|
|
112
|
+
return ones[num] ?? ''
|
|
107
113
|
}
|
|
108
114
|
if (numString.length === 2) {
|
|
109
|
-
return tens[numString[0]] +
|
|
115
|
+
return tens[numString[0]] + ' ' + ones[numString[1]]
|
|
110
116
|
}
|
|
111
117
|
if (numString.length == 3) {
|
|
112
|
-
if (numString[1] ===
|
|
113
|
-
|
|
118
|
+
if (numString[1] === '0' && numString[2] === '0')
|
|
119
|
+
return ones[numString[0]] + ' hundred'
|
|
120
|
+
else
|
|
121
|
+
return ones[numString[0]] + ' hundred and ' + humanize(+((numString[1] || '') + numString[2]), slugify2)
|
|
114
122
|
}
|
|
115
123
|
if (numString.length === 4) {
|
|
116
|
-
const end = +((numString[1] ||
|
|
117
|
-
if (end === 0)
|
|
118
|
-
|
|
119
|
-
|
|
124
|
+
const end = +((numString[1] || '') + numString[2] + numString[3])
|
|
125
|
+
if (end === 0)
|
|
126
|
+
return ones[numString[0]] + ' thousand'
|
|
127
|
+
if (end < 100)
|
|
128
|
+
return ones[numString[0]] + ' thousand and ' + humanize(end, slugify2)
|
|
129
|
+
return ones[numString[0]] + ' thousand ' + humanize(end, slugify2)
|
|
120
130
|
}
|
|
121
|
-
return num
|
|
122
|
-
},
|
|
131
|
+
return num
|
|
132
|
+
}, 'humanize')
|
|
123
133
|
var toBytes = /* @__PURE__ */ __name((bytes, decimals = 2, bits = false) => {
|
|
124
134
|
if (!bytes || isNaN(bytes)) {
|
|
125
|
-
return bits ?
|
|
135
|
+
return bits ? '0 B' : '0 Bytes'
|
|
126
136
|
}
|
|
127
|
-
const base = bits ? 1e3 : 1024
|
|
128
|
-
const dm = decimals < 0 ? 0 : decimals
|
|
137
|
+
const base = bits ? 1e3 : 1024
|
|
138
|
+
const dm = decimals < 0 ? 0 : decimals
|
|
129
139
|
const sizes = bits ? [
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
'B',
|
|
141
|
+
'KB',
|
|
142
|
+
'MB',
|
|
143
|
+
'GB',
|
|
144
|
+
'TB',
|
|
145
|
+
'PB',
|
|
146
|
+
'EB',
|
|
147
|
+
'ZB',
|
|
148
|
+
'YB'
|
|
139
149
|
] : [
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
]
|
|
150
|
-
const index = Math.floor(Math.log(bytes) / Math.log(base))
|
|
151
|
-
const value = parseFloat((bytes / Math.pow(base, index)).toFixed(dm))
|
|
152
|
-
return `${value} ${sizes[index]}
|
|
153
|
-
},
|
|
150
|
+
'Bytes',
|
|
151
|
+
'KiB',
|
|
152
|
+
'MiB',
|
|
153
|
+
'GiB',
|
|
154
|
+
'TiB',
|
|
155
|
+
'PiB',
|
|
156
|
+
'EiB',
|
|
157
|
+
'ZiB',
|
|
158
|
+
'YiB'
|
|
159
|
+
]
|
|
160
|
+
const index = Math.floor(Math.log(bytes) / Math.log(base))
|
|
161
|
+
const value = parseFloat((bytes / Math.pow(base, index)).toFixed(dm))
|
|
162
|
+
return `${value} ${sizes[index]}`
|
|
163
|
+
}, 'toBytes')
|
|
154
164
|
var toHumanTime = /* @__PURE__ */ __name((seconds = 0, worded = false) => {
|
|
155
|
-
if (isNaN(seconds) || seconds < 0)
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
const
|
|
165
|
+
if (isNaN(seconds) || seconds < 0)
|
|
166
|
+
seconds = 0
|
|
167
|
+
const hours = Math.floor(seconds / 3600)
|
|
168
|
+
const minutes = Math.floor(seconds % 3600 / 60)
|
|
169
|
+
const secs = Math.floor(seconds % 60)
|
|
159
170
|
if (worded) {
|
|
160
|
-
const parts = []
|
|
161
|
-
if (hours)
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
171
|
+
const parts = []
|
|
172
|
+
if (hours)
|
|
173
|
+
parts.push(`${hours}hr`)
|
|
174
|
+
if (minutes)
|
|
175
|
+
parts.push(`${minutes}min`)
|
|
176
|
+
if (secs || !hours && !minutes)
|
|
177
|
+
parts.push(`${secs}sec`)
|
|
178
|
+
return parts.join(' ')
|
|
165
179
|
}
|
|
166
|
-
const hh = hours > 0 ? `${hours}:` :
|
|
167
|
-
const mm = (hours > 0 && minutes < 10 ? `0${minutes}` : minutes) +
|
|
168
|
-
const ss = secs < 10 ? `0${secs}` : secs
|
|
169
|
-
return `${hh}${mm}${ss}
|
|
170
|
-
},
|
|
180
|
+
const hh = hours > 0 ? `${hours}:` : ''
|
|
181
|
+
const mm = (hours > 0 && minutes < 10 ? `0${minutes}` : minutes) + ':'
|
|
182
|
+
const ss = secs < 10 ? `0${secs}` : secs
|
|
183
|
+
return `${hh}${mm}${ss}`
|
|
184
|
+
}, 'toHumanTime')
|
|
171
185
|
|
|
172
186
|
// src/Helpers/Obj.ts
|
|
173
187
|
var dot = /* @__PURE__ */ __name((obj) => {
|
|
174
|
-
const result = {}
|
|
175
|
-
const recurse = /* @__PURE__ */ __name((o, prefix =
|
|
188
|
+
const result = {}
|
|
189
|
+
const recurse = /* @__PURE__ */ __name((o, prefix = '') => {
|
|
176
190
|
for (const [key, value] of Object.entries(o)) {
|
|
177
|
-
const newKey = prefix ? `${prefix}.${key}` : key
|
|
178
|
-
if (value && typeof value ===
|
|
179
|
-
recurse(value, newKey)
|
|
191
|
+
const newKey = prefix ? `${prefix}.${key}` : key
|
|
192
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
193
|
+
recurse(value, newKey)
|
|
180
194
|
} else {
|
|
181
|
-
result[newKey] = value
|
|
195
|
+
result[newKey] = value
|
|
182
196
|
}
|
|
183
197
|
}
|
|
184
|
-
},
|
|
185
|
-
recurse(obj)
|
|
186
|
-
return result
|
|
187
|
-
},
|
|
198
|
+
}, 'recurse')
|
|
199
|
+
recurse(obj)
|
|
200
|
+
return result
|
|
201
|
+
}, 'dot')
|
|
188
202
|
var extractProperties = /* @__PURE__ */ __name((obj, keys = []) => {
|
|
189
203
|
return Object.fromEntries(keys.map((key) => [
|
|
190
204
|
key,
|
|
191
205
|
obj[key]
|
|
192
|
-
]))
|
|
193
|
-
},
|
|
206
|
+
]))
|
|
207
|
+
}, 'extractProperties')
|
|
194
208
|
var getValue = /* @__PURE__ */ __name((key, item) => {
|
|
195
209
|
if (Array.isArray(key)) {
|
|
196
|
-
const [parent, child] = key
|
|
210
|
+
const [parent, child] = key
|
|
197
211
|
if (child !== void 0) {
|
|
198
|
-
return String(item?.[parent]?.[child] ?? item?.[parent] ?? `${String(parent)}.${String(child)}`)
|
|
212
|
+
return String(item?.[parent]?.[child] ?? item?.[parent] ?? `${String(parent)}.${String(child)}`)
|
|
199
213
|
}
|
|
200
|
-
return String(item?.[parent] ?? parent)
|
|
214
|
+
return String(item?.[parent] ?? parent)
|
|
201
215
|
}
|
|
202
|
-
return String(item?.[key] ?? key)
|
|
203
|
-
},
|
|
216
|
+
return String(item?.[key] ?? key)
|
|
217
|
+
}, 'getValue')
|
|
204
218
|
var modObj = /* @__PURE__ */ __name((obj, callback) => {
|
|
205
219
|
return Object.fromEntries(Object.entries(obj).map(([key, value]) => callback([
|
|
206
220
|
key,
|
|
207
221
|
value
|
|
208
|
-
])))
|
|
209
|
-
},
|
|
222
|
+
])))
|
|
223
|
+
}, 'modObj')
|
|
210
224
|
function safeDot(data, key) {
|
|
211
|
-
if (!key)
|
|
212
|
-
|
|
225
|
+
if (!key)
|
|
226
|
+
return data
|
|
227
|
+
return key.split('.').reduce((acc, k) => acc?.[k], data)
|
|
213
228
|
}
|
|
214
|
-
__name(safeDot,
|
|
229
|
+
__name(safeDot, 'safeDot')
|
|
215
230
|
var setNested = /* @__PURE__ */ __name((obj, key, value) => {
|
|
216
|
-
if (!key.includes(
|
|
217
|
-
obj[key] = value
|
|
218
|
-
return
|
|
231
|
+
if (!key.includes('.')) {
|
|
232
|
+
obj[key] = value
|
|
233
|
+
return
|
|
219
234
|
}
|
|
220
|
-
const parts = key.split(
|
|
221
|
-
let current = obj
|
|
235
|
+
const parts = key.split('.')
|
|
236
|
+
let current = obj
|
|
222
237
|
for (let i = 0; i < parts.length; i++) {
|
|
223
|
-
const part = parts[i]
|
|
238
|
+
const part = parts[i]
|
|
224
239
|
if (i === parts.length - 1) {
|
|
225
|
-
current[part] = value
|
|
240
|
+
current[part] = value
|
|
226
241
|
} else {
|
|
227
|
-
if (typeof current[part] !==
|
|
228
|
-
current[part] = {}
|
|
242
|
+
if (typeof current[part] !== 'object' || current[part] === null) {
|
|
243
|
+
current[part] = {}
|
|
229
244
|
}
|
|
230
|
-
current = current[part]
|
|
245
|
+
current = current[part]
|
|
231
246
|
}
|
|
232
247
|
}
|
|
233
|
-
},
|
|
234
|
-
var slugifyKeys = /* @__PURE__ */ __name((obj, only = [], separator =
|
|
235
|
-
const slugify2 = /* @__PURE__ */ __name((key) => key.replace(/([a-z])([A-Z])/g, `$1${separator}$2`).replace(/[\s\W]+/g, separator).replace(new RegExp(`${separator}{2,}`,
|
|
236
|
-
let entries = Object.entries(obj)
|
|
248
|
+
}, 'setNested')
|
|
249
|
+
var slugifyKeys = /* @__PURE__ */ __name((obj, only = [], separator = '_') => {
|
|
250
|
+
const slugify2 = /* @__PURE__ */ __name((key) => key.replace(/([a-z])([A-Z])/g, `$1${separator}$2`).replace(/[\s\W]+/g, separator).replace(new RegExp(`${separator}{2,}`, 'g'), separator).replace(new RegExp(`^${separator}|${separator}$`, 'g'), '').toLowerCase(), 'slugify')
|
|
251
|
+
let entries = Object.entries(obj)
|
|
237
252
|
if (only.length) {
|
|
238
|
-
entries = entries.filter(([key]) => only.includes(key))
|
|
253
|
+
entries = entries.filter(([key]) => only.includes(key))
|
|
239
254
|
}
|
|
240
255
|
return Object.fromEntries(entries.map(([key, value]) => [
|
|
241
256
|
slugify2(key),
|
|
242
257
|
value
|
|
243
|
-
]))
|
|
244
|
-
},
|
|
258
|
+
]))
|
|
259
|
+
}, 'slugifyKeys')
|
|
245
260
|
|
|
246
261
|
// src/Helpers/Str.ts
|
|
247
262
|
var after = /* @__PURE__ */ __name((value, search) => {
|
|
248
|
-
if (!search)
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
263
|
+
if (!search)
|
|
264
|
+
return value
|
|
265
|
+
const index = value.indexOf(search)
|
|
266
|
+
return index !== -1 ? value.slice(index + search.length) : value
|
|
267
|
+
}, 'after')
|
|
252
268
|
var afterLast = /* @__PURE__ */ __name((value, search) => {
|
|
253
|
-
if (!search)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
269
|
+
if (!search)
|
|
270
|
+
return value
|
|
271
|
+
const lastIndex = value.lastIndexOf(search)
|
|
272
|
+
return lastIndex !== -1 ? value.slice(lastIndex + search.length) : value
|
|
273
|
+
}, 'afterLast')
|
|
257
274
|
var before = /* @__PURE__ */ __name((value, search) => {
|
|
258
|
-
if (!search)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
275
|
+
if (!search)
|
|
276
|
+
return value
|
|
277
|
+
const index = value.indexOf(search)
|
|
278
|
+
return index !== -1 ? value.slice(0, index) : value
|
|
279
|
+
}, 'before')
|
|
262
280
|
var beforeLast = /* @__PURE__ */ __name((value, search) => {
|
|
263
|
-
if (!search)
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
281
|
+
if (!search)
|
|
282
|
+
return value
|
|
283
|
+
const lastIndex = value.lastIndexOf(search)
|
|
284
|
+
return lastIndex !== -1 ? value.slice(0, lastIndex) : value
|
|
285
|
+
}, 'beforeLast')
|
|
267
286
|
function capitalize(str) {
|
|
268
|
-
if (!str)
|
|
269
|
-
|
|
287
|
+
if (!str)
|
|
288
|
+
return ''
|
|
289
|
+
return str[0].toUpperCase() + str.slice(1)
|
|
270
290
|
}
|
|
271
|
-
__name(capitalize,
|
|
291
|
+
__name(capitalize, 'capitalize')
|
|
272
292
|
var pluralize = /* @__PURE__ */ __name((word, count) => {
|
|
273
|
-
if (count === 1)
|
|
293
|
+
if (count === 1)
|
|
294
|
+
return word
|
|
274
295
|
const irregularPlurals = {
|
|
275
|
-
foot:
|
|
276
|
-
child:
|
|
277
|
-
mouse:
|
|
278
|
-
goose:
|
|
279
|
-
person:
|
|
280
|
-
man:
|
|
281
|
-
woman:
|
|
282
|
-
}
|
|
296
|
+
foot: 'feet',
|
|
297
|
+
child: 'children',
|
|
298
|
+
mouse: 'mice',
|
|
299
|
+
goose: 'geese',
|
|
300
|
+
person: 'people',
|
|
301
|
+
man: 'men',
|
|
302
|
+
woman: 'women'
|
|
303
|
+
}
|
|
283
304
|
if (word in irregularPlurals) {
|
|
284
|
-
return irregularPlurals[word]
|
|
305
|
+
return irregularPlurals[word]
|
|
285
306
|
}
|
|
286
|
-
if (word.endsWith(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
].includes(word[word.length - 2]?.toLowerCase() ??
|
|
293
|
-
return word.slice(0, -1) +
|
|
307
|
+
if (word.endsWith('y') && ![
|
|
308
|
+
'a',
|
|
309
|
+
'e',
|
|
310
|
+
'i',
|
|
311
|
+
'o',
|
|
312
|
+
'u'
|
|
313
|
+
].includes(word[word.length - 2]?.toLowerCase() ?? '')) {
|
|
314
|
+
return word.slice(0, -1) + 'ies'
|
|
294
315
|
}
|
|
295
316
|
if (/(s|ss|sh|ch|x|z)$/i.test(word)) {
|
|
296
|
-
return word +
|
|
317
|
+
return word + 'es'
|
|
297
318
|
}
|
|
298
|
-
return word +
|
|
299
|
-
},
|
|
319
|
+
return word + 's'
|
|
320
|
+
}, 'pluralize')
|
|
300
321
|
var singularize = /* @__PURE__ */ __name((word) => {
|
|
301
322
|
const irregulars = {
|
|
302
|
-
feet:
|
|
303
|
-
children:
|
|
304
|
-
mice:
|
|
305
|
-
geese:
|
|
306
|
-
people:
|
|
307
|
-
men:
|
|
308
|
-
women:
|
|
309
|
-
}
|
|
310
|
-
if (word in irregulars)
|
|
323
|
+
feet: 'foot',
|
|
324
|
+
children: 'child',
|
|
325
|
+
mice: 'mouse',
|
|
326
|
+
geese: 'goose',
|
|
327
|
+
people: 'person',
|
|
328
|
+
men: 'man',
|
|
329
|
+
women: 'woman'
|
|
330
|
+
}
|
|
331
|
+
if (word in irregulars)
|
|
332
|
+
return irregulars[word]
|
|
311
333
|
if (/ies$/i.test(word) && word.length > 3) {
|
|
312
|
-
return word.replace(/ies$/i,
|
|
334
|
+
return word.replace(/ies$/i, 'y')
|
|
313
335
|
}
|
|
314
336
|
if (/(ches|shes|sses|xes|zes)$/i.test(word)) {
|
|
315
|
-
return word.replace(/es$/i,
|
|
337
|
+
return word.replace(/es$/i, '')
|
|
316
338
|
}
|
|
317
339
|
if (/s$/i.test(word) && word.length > 1) {
|
|
318
|
-
return word.replace(/s$/i,
|
|
340
|
+
return word.replace(/s$/i, '')
|
|
319
341
|
}
|
|
320
|
-
return word
|
|
321
|
-
},
|
|
322
|
-
var slugify = /* @__PURE__ */ __name((str, joiner =
|
|
323
|
-
return str.replace(/([a-z])([A-Z])/g, `$1${joiner}$2`).replace(/[\s\W]+/g, joiner).replace(new RegExp(`${joiner}{2,}`,
|
|
324
|
-
},
|
|
325
|
-
var subString = /* @__PURE__ */ __name((str, len, ellipsis =
|
|
326
|
-
if (!str)
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
342
|
+
return word
|
|
343
|
+
}, 'singularize')
|
|
344
|
+
var slugify = /* @__PURE__ */ __name((str, joiner = '_') => {
|
|
345
|
+
return str.replace(/([a-z])([A-Z])/g, `$1${joiner}$2`).replace(/[\s\W]+/g, joiner).replace(new RegExp(`${joiner}{2,}`, 'g'), joiner).replace(new RegExp(`^${joiner}|${joiner}$`, 'g'), '').toLowerCase()
|
|
346
|
+
}, 'slugify')
|
|
347
|
+
var subString = /* @__PURE__ */ __name((str, len, ellipsis = '...') => {
|
|
348
|
+
if (!str)
|
|
349
|
+
return ''
|
|
350
|
+
if (len <= ellipsis.length)
|
|
351
|
+
return ellipsis
|
|
352
|
+
return str.length > len ? str.substring(0, len - ellipsis.length).trimEnd() + ellipsis : str
|
|
353
|
+
}, 'subString')
|
|
330
354
|
var substitute = /* @__PURE__ */ __name((str, data = {}, def) => {
|
|
331
|
-
if (!str || !data)
|
|
332
|
-
|
|
333
|
-
const
|
|
355
|
+
if (!str || !data)
|
|
356
|
+
return void 0
|
|
357
|
+
const regex = /{\s*([a-zA-Z0-9_.]+)\s*}/g
|
|
358
|
+
const flattened = dot(data)
|
|
334
359
|
const out = str.replace(regex, (_, key) => {
|
|
335
|
-
const value = flattened[key]
|
|
336
|
-
return value !== void 0 ? String(value) : def ??
|
|
337
|
-
})
|
|
338
|
-
return out
|
|
339
|
-
},
|
|
340
|
-
var truncate = /* @__PURE__ */ __name((str, len = 20, suffix =
|
|
341
|
-
if (!str)
|
|
342
|
-
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
},
|
|
360
|
+
const value = flattened[key]
|
|
361
|
+
return value !== void 0 ? String(value) : def ?? ''
|
|
362
|
+
})
|
|
363
|
+
return out
|
|
364
|
+
}, 'substitute')
|
|
365
|
+
var truncate = /* @__PURE__ */ __name((str, len = 20, suffix = '...') => {
|
|
366
|
+
if (!str)
|
|
367
|
+
return ''
|
|
368
|
+
const clean = str.replace(/<[^>]+>/g, '')
|
|
369
|
+
const truncated = clean.length > len ? clean.substring(0, len - suffix.length) + suffix : clean
|
|
370
|
+
return truncated.replace(/\n/g, ' ').replace(new RegExp(`\\s+${suffix.replace(/\./g, '\\.')}$`), suffix)
|
|
371
|
+
}, 'truncate')
|
|
346
372
|
export {
|
|
347
373
|
abbreviate,
|
|
348
374
|
after,
|
|
@@ -368,5 +394,5 @@ export {
|
|
|
368
394
|
toBytes,
|
|
369
395
|
toHumanTime,
|
|
370
396
|
truncate
|
|
371
|
-
}
|
|
397
|
+
}
|
|
372
398
|
//# sourceMappingURL=index.js.map
|