mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-17 19:21:20 +03:00
feat(html): @bbob/html now can be used without @bbob/core
This commit is contained in:
@@ -14,12 +14,27 @@ const getNodeLength = (node) => {
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Appends value to Tag Node
|
||||
* @param {TagNode} node
|
||||
* @param value
|
||||
*/
|
||||
const appendToNode = (node, value) => {
|
||||
node.content.push(value);
|
||||
};
|
||||
|
||||
/**
|
||||
* Replaces " to &qquot;
|
||||
* @param {String} value
|
||||
*/
|
||||
const escapeQuote = value => value.replace(/"/g, '"');
|
||||
|
||||
/**
|
||||
* Acept name and value and return valid html5 attribute string
|
||||
* @param {String} name
|
||||
* @param {String} value
|
||||
* @return {string}
|
||||
*/
|
||||
const attrValue = (name, value) => {
|
||||
const type = typeof value;
|
||||
|
||||
@@ -33,7 +48,17 @@ const attrValue = (name, value) => {
|
||||
return types[type] ? types[type]() : '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Transforms attrs to html params string
|
||||
* @param values
|
||||
*/
|
||||
const attrsToString = values =>
|
||||
Object.keys(values)
|
||||
.reduce((arr, key) => [...arr, attrValue(key, values[key])], [''])
|
||||
.join(' ');
|
||||
|
||||
export {
|
||||
attrsToString,
|
||||
attrValue,
|
||||
appendToNode,
|
||||
getNodeLength,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
attrsToString,
|
||||
attrValue,
|
||||
appendToNode,
|
||||
getNodeLength,
|
||||
@@ -69,5 +70,13 @@ describe('@bbob/plugin-helper', () => {
|
||||
|
||||
test('isEOL', () => {
|
||||
expect(isEOL('\n')).toBe(true)
|
||||
});
|
||||
|
||||
test('attrsToString', () => {
|
||||
expect(attrsToString({
|
||||
tag: 'test',
|
||||
foo: 'bar',
|
||||
disabled: true
|
||||
})).toBe(` tag="test" foo="bar" disabled`)
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user