@mythpe/quasar-ui-qui 0.4.21 → 0.4.22
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/package.json +1 -1
- package/src/utils/Helpers.ts +22 -0
- package/src/utils/Str.ts +26 -0
package/package.json
CHANGED
package/src/utils/Helpers.ts
CHANGED
|
@@ -349,5 +349,27 @@ export const Helpers = {
|
|
|
349
349
|
},
|
|
350
350
|
uniq<T> (array: T[]): T[] {
|
|
351
351
|
return [...new Set(array)]
|
|
352
|
+
},
|
|
353
|
+
shuffle<T = any> (array: readonly T[]): T[] {
|
|
354
|
+
const newArray = [...(array || [])]
|
|
355
|
+
for (let i = newArray.length - 1; i > 0; i--) {
|
|
356
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
357
|
+
[newArray[i], newArray[j]] = [newArray[j], newArray[i]] as [T, T]
|
|
358
|
+
}
|
|
359
|
+
// console.log(newArray)
|
|
360
|
+
return newArray
|
|
361
|
+
},
|
|
362
|
+
detectWebPlatform (): 'ios' | 'android' | 'other' {
|
|
363
|
+
let userAgent = navigator.userAgent || navigator.vendor
|
|
364
|
+
userAgent = userAgent ? userAgent.toLowerCase() : ''
|
|
365
|
+
if (/ipad|iphone|ipod/g.test(userAgent)) {
|
|
366
|
+
return 'ios'
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (/android/i.test(userAgent)) {
|
|
370
|
+
return 'android'
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return 'other'
|
|
352
374
|
}
|
|
353
375
|
}
|
package/src/utils/Str.ts
CHANGED
|
@@ -213,6 +213,32 @@ export const Str = {
|
|
|
213
213
|
}
|
|
214
214
|
return r + (pEnd || '')
|
|
215
215
|
})
|
|
216
|
+
},
|
|
217
|
+
ucFirst (str: any) {
|
|
218
|
+
if (!str) return str
|
|
219
|
+
return str?.toString?.()?.charAt?.(0)?.toUpperCase() + str?.toString?.()?.slice?.(1)?.toLowerCase?.()
|
|
220
|
+
},
|
|
221
|
+
toAlphaNumerals (num: number, options: { uppercase?: boolean; startFromZero?: boolean } = {}): string {
|
|
222
|
+
const { uppercase = true, startFromZero = false } = options
|
|
223
|
+
num = parseInt(num?.toString?.() || '0') || 0
|
|
224
|
+
if (num <= 0) {
|
|
225
|
+
if (!startFromZero) {
|
|
226
|
+
return ''
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (startFromZero && `${num}` === '0') return uppercase ? 'A' : 'a'
|
|
230
|
+
|
|
231
|
+
let adjustedNum = startFromZero ? num + 1 : num
|
|
232
|
+
let result = ''
|
|
233
|
+
|
|
234
|
+
while (adjustedNum > 0) {
|
|
235
|
+
adjustedNum--
|
|
236
|
+
const charCode = (adjustedNum % 26) + (uppercase ? 65 : 97)
|
|
237
|
+
result = String.fromCharCode(charCode) + result
|
|
238
|
+
adjustedNum = Math.floor(adjustedNum / 26)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return result
|
|
216
242
|
}
|
|
217
243
|
}
|
|
218
244
|
|