feat: better definitions

This commit is contained in:
cudr
2019-10-06 23:56:27 +03:00
parent fbcbef02af
commit 86e9e77410
10 changed files with 49 additions and 31 deletions

View File

@@ -0,0 +1,15 @@
export type Hex = string
const hexGen = (len: number = 12): Hex => {
const maxlen = 8
const min = Math.pow(16, Math.min(len, maxlen) - 1)
const max = Math.pow(16, Math.min(len, maxlen)) - 1
const n = Math.floor(Math.random() * (max - min + 1)) + min
let r = n.toString(16)
while (r.length < len) {
r = r + hexGen(len - maxlen)
}
return r
}
export default hexGen

View File

@@ -1,4 +1,5 @@
import toSync from './toSync'
import hexGen from './hexGen'
export const toJS = node => JSON.parse(JSON.stringify(node))
@@ -6,4 +7,4 @@ export const cloneNode = node => toSync(toJS(node))
const toSlatePath = path => (path ? path.filter(d => Number.isInteger(d)) : [])
export { toSync, toSlatePath }
export { toSync, toSlatePath, hexGen }