1.0.4 • Published 12 months ago

@oasis-end/utils v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

The end of the oasis is still an oasis. There are some useful utils.

Docs

floatAdd

Avoiding precision problems when adding float numbers.

import { floatAdd } from '@oasis-end/utils'

floatAdd(0.1, 0.2) // the result is 0.3
0.1 + 0.2 // the result is 0.30000000000000004

unique

High-performance array unique.

import { unique } from '@oasis-end/utils'

unique([1, 2, 1, 2]) // the result is [1, 2]
unique([
    { id: 1 }, { id: 2 },
    { id: 1 }, { id: 2 }
], 'id') // the result is [{ id: 1 }, { id: 2 }]
unique([
    { id: 1 }, { id: 2 },
    { id: 1 }, { id: 2 }
], item => item.id) // the result is [{ id: 1 }, { id: 2 }]

treeMap

Map properties for tree array.

import { treeMap } from '@oasis-end/utils'

unique([
    { name: 'A' },
    { name: 'B' },
    { name: 'C' },
    { name: 'D', children: [ { name: 'E' } ] }
], (item) => {
    return { name: `${item.name} is my name` }
})
// the result is
// [
//     { name: 'A is my name' },
//     { name: 'B is my name' },
//     { name: 'C is my name' },
//     { name: 'D is my name', children: [ { name: 'E is my name' } ] }
// ]
1.0.2

1 year ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.1

3 years ago

1.0.0

3 years ago