mirror of https://github.com/sgoudham/carbon.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
586 B
JavaScript
24 lines
586 B
JavaScript
import morph from 'morphmorph'
|
|
const KEY = 'CARBON_STATE'
|
|
|
|
const assign = morph.assign(KEY)
|
|
|
|
const parse = v => {
|
|
try {
|
|
return JSON.parse(v)
|
|
} catch (e) {}
|
|
}
|
|
|
|
const escapeHtml = s =>
|
|
s
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/\//g, '/')
|
|
|
|
export const parseRGBA = obj => `rgba(${obj.r},${obj.g},${obj.b},${obj.a})`
|
|
|
|
export const getState = morph.compose(parse, escapeHtml, morph.get(KEY))
|
|
export const saveState = (window, v) => assign(window, JSON.stringify(v))
|
|
|
|
export const capitalizeFirstLetter = s => s.charAt(0).toUpperCase() + s.slice(1)
|