This commit is contained in:
toir 2021-03-14 20:53:41 +05:00
parent a718a7e9c3
commit d349aaecab
6 changed files with 14 additions and 15635 deletions

4
.gitignore vendored
View File

@ -3,4 +3,6 @@ node_modules
dist dist
sandbox sandbox
stash stash
coverage coverage
package-lock.json
.idea

15632
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^5.2.5", "@commitlint/cli": "^5.2.5",
"@commitlint/config-conventional": "^6.1.3", "@commitlint/config-conventional": "^12.1.0",
"algoliasearch": "^3.27.1", "algoliasearch": "^3.27.1",
"babel-cli": "^6.24.1", "babel-cli": "^6.24.1",
"babel-loader": "^7.1.1", "babel-loader": "^7.1.1",
@ -48,7 +48,7 @@
"eslint-plugin-import": "^2.5.0", "eslint-plugin-import": "^2.5.0",
"eslint-plugin-prettier": "^2.5.0", "eslint-plugin-prettier": "^2.5.0",
"html-minifier": "^3.5.8", "html-minifier": "^3.5.8",
"husky": "^0.14.3", "husky": "^5.1.3",
"jest": "^22.4.4", "jest": "^22.4.4",
"lint-staged": "^6.0.0", "lint-staged": "^6.0.0",
"npm-run-all": "^4.1.2", "npm-run-all": "^4.1.2",

View File

@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`check function replace with empty [data-feather] attribute 1`] = `"<i data-feather=\\"\\"></i><span data-feather=\\"\\"></span>"`;
exports[`copies placeholder element attributes to <svg> tag 1`] = `"<i data-feather=\\"icon1\\" id=\\"test\\" class=\\"foo bar\\" stroke-width=\\"1\\"></i>"`; exports[`copies placeholder element attributes to <svg> tag 1`] = `"<i data-feather=\\"icon1\\" id=\\"test\\" class=\\"foo bar\\" stroke-width=\\"1\\"></i>"`;
exports[`copies placeholder element attributes to <svg> tag 2`] = `"<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"24\\" height=\\"24\\" viewBox=\\"0 0 24 24\\" fill=\\"none\\" stroke=\\"currentColor\\" stroke-width=\\"1\\" stroke-linecap=\\"round\\" stroke-linejoin=\\"round\\" class=\\"feather feather-icon1 foo bar\\" id=\\"test\\"><line x1=\\"23\\" y1=\\"1\\" x2=\\"1\\" y2=\\"23\\"></line><line x1=\\"1\\" y1=\\"1\\" x2=\\"23\\" y2=\\"23\\"></line></svg>"`; exports[`copies placeholder element attributes to <svg> tag 2`] = `"<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"24\\" height=\\"24\\" viewBox=\\"0 0 24 24\\" fill=\\"none\\" stroke=\\"currentColor\\" stroke-width=\\"1\\" stroke-linecap=\\"round\\" stroke-linejoin=\\"round\\" class=\\"feather feather-icon1 foo bar\\" id=\\"test\\"><line x1=\\"23\\" y1=\\"1\\" x2=\\"1\\" y2=\\"23\\"></line><line x1=\\"1\\" y1=\\"1\\" x2=\\"23\\" y2=\\"23\\"></line></svg>"`;

View File

@ -15,6 +15,12 @@ test('replaces [data-feather] elements with SVG markup', () => {
expect(document.body.innerHTML).toMatchSnapshot(); expect(document.body.innerHTML).toMatchSnapshot();
}); });
test('check function replace with empty [data-feather] attribute', () => {
document.body.innerHTML = '<i data-feather=""></i><span data-feather=""></i>';
expect(document.body.innerHTML).toMatchSnapshot();
replace();
});
test('copies placeholder element attributes to <svg> tag', () => { test('copies placeholder element attributes to <svg> tag', () => {
document.body.innerHTML = document.body.innerHTML =
'<i data-feather="icon1" id="test" class="foo bar" stroke-width="1"></i>'; '<i data-feather="icon1" id="test" class="foo bar" stroke-width="1"></i>';

View File

@ -31,6 +31,7 @@ function replaceElement(element, attrs = {}) {
const name = elementAttrs['data-feather']; const name = elementAttrs['data-feather'];
delete elementAttrs['data-feather']; delete elementAttrs['data-feather'];
if (typeof icons[name] === 'undefined') return;
const svgString = icons[name].toSvg({ const svgString = icons[name].toSvg({
...attrs, ...attrs,
...elementAttrs, ...elementAttrs,