diff --git a/.npmignore b/.npmignore new file mode 100644 index 000000000..1dcd77402 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +.github +packages +stats +build diff --git a/package.json b/package.json index b08cf0314..f0ee91a94 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "amdName": "featherity", "license": "ISC", "version": "0.1.0-alpha.0", - "private": true, "source": "build/featherity.js", "main": "dist/cjs/featherity.js", "main:umd": "dist/umd/featherity.js", diff --git a/src/featherity.js b/src/featherity.js new file mode 100644 index 000000000..9c4e7cf3a --- /dev/null +++ b/src/featherity.js @@ -0,0 +1,27 @@ +import replaceElement from './replaceElement'; + +/* eslint-disable */ +/* + Main library entry +*/ +export default ({ icons = {}, nameAttr = 'data-feather', attrs = {} }) => { + if (!Object.values(icons).length) { + throw new Error( + "Please provide an icons object.\nIf you want to use all the icons you can import it like:\n `import featherity, { icons } from 'featherity';\nfeather({icons});`", + ); + } + + if (typeof document === 'undefined') { + throw new Error('`feather.replace()` only works in a browser environment.'); + } + + const elementsToReplace = document.querySelectorAll(`[${nameAttr}]`); + + Array.from(elementsToReplace).forEach(element => replaceElement(element, {nameAttr, icons, attrs})); + }; + +/* + Icons exports. +*/ +export * as icons from './icons/index'; +export * from './icons/index';