mirror of
https://github.com/cudr/slate-collaborative.git
synced 2026-03-02 03:40:18 +00:00
feat: better definitions
This commit is contained in:
15
packages/bridge/src/utils/hexGen.ts
Normal file
15
packages/bridge/src/utils/hexGen.ts
Normal 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
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user