mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
feat(plugin-helper): move getUniqAttr from preset to plugin helper (#63)
This commit is contained in:
committed by
GitHub
parent
2cfe729d75
commit
f28f19e64c
@@ -63,11 +63,23 @@ const attrsToString = (values) => {
|
|||||||
.join(' ');
|
.join(' ');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets value from
|
||||||
|
* @example
|
||||||
|
* getUniqAttr({ 'foo': true, 'bar': bar' }) => 'bar'
|
||||||
|
* @param attrs
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
const getUniqAttr = (attrs) => Object
|
||||||
|
.keys(attrs)
|
||||||
|
.reduce((res, key) => (attrs[key] === key ? attrs[key] : null), null);
|
||||||
|
|
||||||
export {
|
export {
|
||||||
attrsToString,
|
attrsToString,
|
||||||
attrValue,
|
attrValue,
|
||||||
appendToNode,
|
appendToNode,
|
||||||
getNodeLength,
|
getNodeLength,
|
||||||
|
getUniqAttr,
|
||||||
isTagNode,
|
isTagNode,
|
||||||
isStringNode,
|
isStringNode,
|
||||||
isEOL,
|
isEOL,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
attrValue,
|
attrValue,
|
||||||
appendToNode,
|
appendToNode,
|
||||||
getNodeLength,
|
getNodeLength,
|
||||||
|
getUniqAttr,
|
||||||
isTagNode,
|
isTagNode,
|
||||||
isStringNode,
|
isStringNode,
|
||||||
isEOL,
|
isEOL,
|
||||||
@@ -78,9 +79,17 @@ describe('@bbob/plugin-helper', () => {
|
|||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
disabled: true
|
disabled: true
|
||||||
})).toBe(` tag="test" foo="bar" disabled`)
|
})).toBe(` tag="test" foo="bar" disabled`)
|
||||||
})
|
});
|
||||||
|
|
||||||
test('attrsToString undefined', () => {
|
test('attrsToString undefined', () => {
|
||||||
expect(attrsToString(undefined)).toBe('')
|
expect(attrsToString(undefined)).toBe('')
|
||||||
})
|
});
|
||||||
|
|
||||||
|
test('getUniqAttr with unq attr', () => {
|
||||||
|
expect(getUniqAttr({foo: true, 'http://bar.com': 'http://bar.com'})).toBe('http://bar.com')
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getUniqAttr without unq attr', () => {
|
||||||
|
expect(getUniqAttr({foo: true})).toBe(null)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable no-plusplus,no-lonely-if */
|
/* eslint-disable no-plusplus,no-lonely-if */
|
||||||
import { isStringNode, isTagNode } from '@bbob/plugin-helper';
|
import { isStringNode, isTagNode, getUniqAttr } from '@bbob/plugin-helper';
|
||||||
import TagNode from '@bbob/plugin-helper/lib/TagNode';
|
import TagNode from '@bbob/plugin-helper/lib/TagNode';
|
||||||
|
|
||||||
const isStartsWith = (node, type) => (node[0] === type);
|
const isStartsWith = (node, type) => (node[0] === type);
|
||||||
@@ -55,10 +55,6 @@ const asListItems = (content) => {
|
|||||||
return [].concat(listItems);
|
return [].concat(listItems);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUniqAttr = (attrs) => Object
|
|
||||||
.keys(attrs)
|
|
||||||
.reduce((res, key) => (attrs[key] === key ? attrs[key] : null), null);
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
b: (node) => ({
|
b: (node) => ({
|
||||||
tag: 'span',
|
tag: 'span',
|
||||||
|
|||||||
Reference in New Issue
Block a user