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