@slate-serializers/utilities
Advanced tools
Comparing version 2.1.6 to 2.2.0
{ | ||
"name": "@slate-serializers/utilities", | ||
"version": "2.1.6", | ||
"version": "2.2.0", | ||
"type": "commonjs", | ||
"dependencies": { | ||
"postcss": "^8.4.24", | ||
"postcss": "8.4.38", | ||
"postcss-js": "^4.0.1", | ||
"tslib": "2.5.0" | ||
"tslib": "2.6.3" | ||
}, | ||
"main": "./src/index.js" | ||
} | ||
} |
export * from './lib/style-object'; | ||
export * from './lib/utilities'; | ||
export * from './lib/blocks'; |
@@ -6,3 +6,2 @@ "use strict"; | ||
tslib_1.__exportStar(require("./lib/utilities"), exports); | ||
tslib_1.__exportStar(require("./lib/blocks"), exports); | ||
//# sourceMappingURL=index.js.map |
export declare const hasLineBreak: (str: string) => boolean; | ||
export declare const prependSpace: (str: string) => string; | ||
export declare const parseStyleCssText: (value: string) => { | ||
[key: string]: string; | ||
}; | ||
export declare const styleToString: (style: { | ||
[key: string]: string; | ||
}) => string; | ||
export declare const isEmptyObject: (obj: any) => any; | ||
@@ -18,16 +12,1 @@ export declare const removeEmpty: (obj: {}) => {}; | ||
export declare const getNested: (obj: any, ...args: string[]) => any; | ||
export declare const encodeBreakingEntities: (str: string) => string; | ||
export declare const decodeBreakingEntities: (str: string) => string; | ||
export declare const intersection: (o1: { | ||
[key: string]: any; | ||
}, o2: { | ||
[key: string]: any; | ||
}) => string[]; | ||
export declare const styleMapToAttribs: ({ elementStyleMap, node, }: { | ||
elementStyleMap: { | ||
[key: string]: string; | ||
}; | ||
node: any; | ||
}) => { | ||
[key: string]: any; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.styleMapToAttribs = exports.intersection = exports.decodeBreakingEntities = exports.encodeBreakingEntities = exports.getNested = exports.removeEmpty = exports.isEmptyObject = exports.styleToString = exports.parseStyleCssText = exports.prependSpace = exports.hasLineBreak = void 0; | ||
exports.getNested = exports.removeEmpty = exports.isEmptyObject = exports.prependSpace = exports.hasLineBreak = void 0; | ||
const hasLineBreak = (str) => str.match(/[\r\n]+/) !== null; | ||
@@ -8,36 +8,2 @@ exports.hasLineBreak = hasLineBreak; | ||
exports.prependSpace = prependSpace; | ||
const camelize = (str) => { | ||
return str.replace(/(?:^|[-])(\w)/g, (a, c) => { | ||
c = a.substring(0, 1) === '-' ? c.toUpperCase() : c; | ||
return c ? c : ''; | ||
}); | ||
}; | ||
const parseStyleCssText = (value) => { | ||
const output = {}; | ||
if (!value) { | ||
return output; | ||
} | ||
const style = value.split(';'); | ||
for (const s of style) { | ||
const rule = s.trim(); | ||
if (rule) { | ||
const ruleParts = rule.split(':'); | ||
const key = camelize(ruleParts[0].trim()); | ||
output[key] = ruleParts[1].trim(); | ||
} | ||
} | ||
return output; | ||
}; | ||
exports.parseStyleCssText = parseStyleCssText; | ||
const styleToString = (style) => { | ||
return Object.keys(style).reduce((acc, key) => acc + | ||
key | ||
.split(/(?=[A-Z])/) | ||
.join('-') | ||
.toLowerCase() + | ||
':' + | ||
style[key] + | ||
';', ''); | ||
}; | ||
exports.styleToString = styleToString; | ||
const isEmptyObject = (obj) => obj && Object.keys(obj).length === 0 && Object.getPrototypeOf(obj) === Object.prototype; | ||
@@ -59,54 +25,2 @@ exports.isEmptyObject = isEmptyObject; | ||
exports.getNested = getNested; | ||
const encodeBreakingEntities = (str) => { | ||
const swapChar = (charToSwap) => { | ||
// that swaps characters to HTML entities | ||
switch (charToSwap) { | ||
case '&': | ||
return '&'; | ||
case '<': | ||
return '<'; | ||
case '>': | ||
return '>'; | ||
default: | ||
return charToSwap; | ||
} | ||
}; | ||
str = str.replace(/[&<>]/g, (match) => { | ||
return swapChar(match); | ||
}); | ||
return str; | ||
}; | ||
exports.encodeBreakingEntities = encodeBreakingEntities; | ||
const decodeBreakingEntities = (str) => { | ||
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | ||
}; | ||
exports.decodeBreakingEntities = decodeBreakingEntities; | ||
const intersection = (o1, o2) => { | ||
return Object.keys(o1) | ||
.concat(Object.keys(o2)) | ||
.sort() | ||
.reduce((r, a, i, aa) => { | ||
if (i && aa[i - 1] === a) { | ||
r.push(a); | ||
} | ||
return r; | ||
}, []); | ||
}; | ||
exports.intersection = intersection; | ||
const styleMapToAttribs = ({ elementStyleMap, node, }) => { | ||
let attribs = {}; | ||
const styleAttrs = {}; | ||
Object.keys(elementStyleMap).forEach((slateKey) => { | ||
const cssProperty = elementStyleMap[slateKey]; | ||
const cssValue = node[slateKey]; | ||
if (cssValue) { | ||
styleAttrs[cssProperty] = cssValue; | ||
} | ||
}); | ||
if (!(0, exports.isEmptyObject)(styleAttrs)) { | ||
attribs = Object.assign(Object.assign({}, attribs), { style: (0, exports.styleToString)(styleAttrs) }); | ||
} | ||
return (0, exports.isEmptyObject)(attribs) ? {} : attribs; | ||
}; | ||
exports.styleMapToAttribs = styleMapToAttribs; | ||
//# sourceMappingURL=utilities.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
5648
12
66
+ Addedpostcss@8.4.38(transitive)
+ Addedtslib@2.6.3(transitive)
- Removedpostcss@8.4.49(transitive)
- Removedtslib@2.5.0(transitive)
Updatedpostcss@8.4.38
Updatedtslib@2.6.3