cudr_slate-collaborative/packages/bridge/src/utils/index.ts

18 lines
415 B
TypeScript
Raw Normal View History

2019-10-05 08:44:49 +00:00
import toSync from './toSync'
2019-10-06 20:56:27 +00:00
import hexGen from './hexGen'
2019-10-05 08:44:49 +00:00
2019-10-19 20:29:09 +00:00
const toJS = node => {
2019-10-10 19:45:31 +00:00
try {
return JSON.parse(JSON.stringify(node))
} catch (e) {
console.error('Convert to js failed!!! Return null')
2019-10-10 19:45:31 +00:00
return null
}
}
2019-10-05 08:44:49 +00:00
2019-10-19 20:29:09 +00:00
const cloneNode = node => toSync(toJS(node))
2019-10-05 08:44:49 +00:00
const toSlatePath = path => (path ? path.filter(d => Number.isInteger(d)) : [])
2019-10-19 20:29:09 +00:00
export { toSync, toJS, toSlatePath, hexGen, cloneNode }