@kokimin/utils
v0.0.11
Published
### Import
Downloads
1,122
Readme
Usage
Import
import _utils from '@kokimin/utils'
// or
import { uniq, orderBy, dateFormat } from '@kokimin/utils'Examples
Array
import { uniq, union, head, last } from '@kokimin/utils'
uniq([1, 2, 2, 3]) // [1, 2, 3]
union([1, 2], [2, 3]) // [1, 2, 3]
head([10, 20, 30]) // 10
last([10, 20, 30]) // 30Collection
import { sortBy, orderBy } from '@kokimin/utils'
orderBy(
[
{ name: 'Tom', age: 30 },
{ name: 'Jane', age: 20 }
],
['age'],
['asc']
)Date (Dayjs-based)
import { dateFormat, searchDefaultDate } from '@kokimin/utils'
dateFormat(new Date(), 'YYYY-MM-DD')
searchDefaultDate('thisMonth')
// ['2025-12-01', '2025-12-31']Formatter
import { currencyFormatter, phoneFormatter } from '@kokimin/utils'
currencyFormatter(1234567) // "1,234,567"
phoneFormatter('01012341234') // "010-1234-1234"Object
import { omit, has, merge } from '@kokimin/utils'
omit({ a: 1, b: 2 }, 'b') // { a: 1 }
has({ a: { b: 1 } }, 'a.b') // true
merge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }String
import { padStart, trim } from '@kokimin/utils'
padStart('5', 3, '0') // "005"
trim(' hello ') // "hello"Number
import { random, numberArrayMax } from '@kokimin/utils'
random(1, 10)
numberArrayMax([3, 9, 5]) // 9Clone & Validation
import { cloneDeep, isEmpty } from '@kokimin/utils'
cloneDeep({ a: 1 })
isEmpty({}) // trueUI Alerts (SweetAlert2)
import { alert, confirm, toastSuccess } from '@kokimin/utils'
await alert('Notice', 'Saved successfully')
const ok = await confirm('Confirm', 'Delete this item?')
toastSuccess('Success', 'Completed')API
Array
concat(array, ...values)uniq(array)union(...arrays)intersection(...arrays)head(array)last(array)flattenDeep(array)flattenDeepAll(array, key?, child?)
Collection
sortBy(collection, iteratees)orderBy(collection, iteratees, orders?)
Common
generateUuid(v?: 'v1' | 'v4')generateRandomNumber(min?, max?)trimStringByByte(str, byteLength)getByteLength(str)
Date
dateFormat(date, format?)quarter(date)calculateDay(options?)searchDefaultDate(type?)
Formatter
currencyFormatter(value, precision?)phoneFormatter(phone?)
Object
assign(object, ...sources)merge(object, ...sources)has(object, path)omit(object, paths)objectEmptyRemove(object)
String
padStart(string, targetLength, padString?)replace(string, pattern, replacement)trim(string, chars?)
Number
random(lower?, upper?, floating?)numberArrayMax(arr)
Alert
alert(title, content)confirm(title, content)toastSuccess(title, content?)toastError(title, content?)close()
Default Export
All utilities are also available via default export:
import _utils from '@kokimin/utils';
_utils.dateFormat(new Date())
_utils.toastSuccess('Done')TypeScript Support
- Built-in
.d.ts - Generic-friendly APIs
- No additional configuration required
License
MIT © kokimin
