Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

purgecss

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

purgecss - npm Package Compare versions

Comparing version 0.19.0 to 0.20.0

9

CHANGELOG.md
# Changelog
# v0.20.0 - 2018-01-31
* https://github.com/FullHuman/purgecss/pull/48, fix https://github.com/FullHuman/purgecss/issues/41
* New option `fontFace` to remove unused font-face declaration
* Remove unused vendor-prefixed keyframes rules
* Update dependencies
# v.0.19.0 - 2018-01-14

@@ -4,0 +13,0 @@

8

flow-typed/index.js

@@ -20,3 +20,4 @@ // @flow

legacy?: boolean,
keyframes?: boolean
keyframes?: boolean,
fontFace?: boolean
}

@@ -33,1 +34,6 @@

}
declare type AtRules = {
keyframes: Array<Object>,
fontFace: Array<Object>
}

2

lib/purgecss.es.js

@@ -1,1 +0,1 @@

import fs from"fs";import glob from"glob";import postcss from"postcss";import selectorParser from"postcss-selector-parser";function normalizeArray(t,e){for(var r=0,o=t.length-1;o>=0;o--){var n=t[o];"."===n?t.splice(o,1):".."===n?(t.splice(o,1),r++):r&&(t.splice(o,1),r--)}if(e)for(;r--;r)t.unshift("..");return t}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,splitPath=function(t){return splitPathRe.exec(t).slice(1)};function resolve(){for(var t="",e=!1,r=arguments.length-1;r>=-1&&!e;r--){var o=r>=0?arguments[r]:"/";if("string"!=typeof o)throw new TypeError("Arguments to path.resolve must be strings");o&&(t=o+"/"+t,e="/"===o.charAt(0))}return t=normalizeArray(filter(t.split("/"),function(t){return!!t}),!e).join("/"),(e?"/":"")+t||"."}function normalize(t){var e=isAbsolute(t),r="/"===substr(t,-1);return(t=normalizeArray(filter(t.split("/"),function(t){return!!t}),!e).join("/"))||e||(t="."),t&&r&&(t+="/"),(e?"/":"")+t}function isAbsolute(t){return"/"===t.charAt(0)}function join(){return normalize(filter(Array.prototype.slice.call(arguments,0),function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))}function relative(t,e){function r(t){for(var e=0;e<t.length&&""===t[e];e++);for(var r=t.length-1;r>=0&&""===t[r];r--);return e>r?[]:t.slice(e,r-e+1)}t=resolve(t).substr(1),e=resolve(e).substr(1);for(var o=r(t.split("/")),n=r(e.split("/")),i=Math.min(o.length,n.length),a=i,s=0;s<i;s++)if(o[s]!==n[s]){a=s;break}var l=[];for(s=a;s<o.length;s++)l.push("..");return(l=l.concat(n.slice(a))).join("/")}var sep="/",delimiter=":";function dirname(t){var e=splitPath(t),r=e[0],o=e[1];return r||o?(o&&(o=o.substr(0,o.length-1)),r+o):"."}function basename(t,e){var r=splitPath(t)[2];return e&&r.substr(-1*e.length)===e&&(r=r.substr(0,r.length-e.length)),r}function extname(t){return splitPath(t)[3]}var path={extname:extname,basename:basename,dirname:dirname,sep:sep,delimiter:delimiter,relative:relative,join:join,isAbsolute:isAbsolute,normalize:normalize,resolve:resolve};function filter(t,e){if(t.filter)return t.filter(e);for(var r=[],o=0;o<t.length;o++)e(t[o],o,t)&&r.push(t[o]);return r}var substr="b"==="ab".substr(-1)?function(t,e,r){return t.substr(e,r)}:function(t,e,r){return e<0&&(e=t.length+e),t.substr(e,r)},defaultOptions={css:[],content:[],extractors:[],whitelist:[],output:void 0,stdout:!1,info:!1,rejected:!1,legacy:!1,keyframes:!1},IGNORE_ANNOTATION="purgecss ignore",CONFIG_FILENAME="purgecss.config.js",ERROR_CONFIG_FILE_LOADING="Error loading the config file",ERROR_MISSING_CONTENT="No content provided.",ERROR_MISSING_CSS="No css provided.",ERROR_EXTRACTER_FAILED="The extractor has failed to extract the selectors.",ERROR_OPTIONS_TYPE="Error Type Options: expected an object",ERROR_OUTPUT_TYPE="Error Type option output: expected a string",ERROR_EXTRACTERS_TYPE="Error Type option extractors: expected an array",ERROR_WHITELIST_TYPE="Error Type option whitelist: expected an array",ERROR_WHITELIST_PATTERNS_TYPE="Error Type option whitelistPatterns: expected an array",ERROR_STDOUT_TYPE="Error Type option stdout: expected a boolean",ERROR_INFO_TYPE="Error Type option info: expected a boolean",ERROR_REJECTED_TYPE="Error Type option rejected: expected a boolean",CSS_WHITELIST=["*","::-webkit-scrollbar","::selection",":root","::before","::after"],SELECTOR_STANDARD_TYPES=["class","id","universal","pseudo"],_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,r,o){return r&&t(e.prototype,r),o&&t(e,o),e}}(),toConsumableArray=function(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)},DefaultExtractor=function(){function t(){classCallCheck(this,t)}return createClass(t,null,[{key:"extract",value:function(t){return t.match(/[A-Za-z0-9_-]+/g)}}]),t}(),LegacyExtractor=function(){function t(){classCallCheck(this,t)}return createClass(t,null,[{key:"extract",value:function(t){return t.split(/[^a-z]/g)}}]),t}(),Purgecss=function(){function t(e){classCallCheck(this,t),this.atRules={keyframes:{}},"string"!=typeof e&&void 0!==e||(e=this.loadConfigFile(e)),this.checkOptions(e),this.options=Object.assign(defaultOptions,e)}return createClass(t,[{key:"loadConfigFile",value:function(t){var e=void 0===t?CONFIG_FILENAME:t,r=void 0;try{var o=path.resolve(process.cwd(),e);r=require(o)}catch(t){throw new Error(ERROR_CONFIG_FILE_LOADING+t.message)}return r}},{key:"checkOptions",value:function(t){if("object"!==(void 0===t?"undefined":_typeof(t)))throw new TypeError(ERROR_OPTIONS_TYPE);if(!t.content||!t.content.length)throw new Error(ERROR_MISSING_CONTENT);if(!t.css||!t.css.length)throw new Error(ERROR_MISSING_CSS);if(t.output&&"string"!=typeof t.output)throw new TypeError(ERROR_OUTPUT_TYPE);if(t.extractors&&!Array.isArray(t.extractors))throw new TypeError(ERROR_EXTRACTERS_TYPE);if(t.whitelist&&!Array.isArray(t.whitelist))throw new TypeError(ERROR_WHITELIST_TYPE);if(t.stdout&&"boolean"!=typeof t.stdout)throw new TypeError(ERROR_STDOUT_TYPE);if(t.info&&"boolean"!=typeof t.info)throw new TypeError(ERROR_INFO_TYPE);if(t.rejected&&"boolean"!=typeof t.rejected)throw new TypeError(ERROR_REJECTED_TYPE);if(t.whitelistPatterns&&!Array.isArray(t.whitelistPatterns))throw new TypeError(ERROR_WHITELIST_PATTERNS_TYPE)}},{key:"purge",value:function(){var t=this.options,e=t.content,r=t.extractors,o=t.css,n=e.filter(function(t){return"string"==typeof t}),i=e.filter(function(t){return"object"===(void 0===t?"undefined":_typeof(t))}),a=this.extractFileSelector(n,r),s=this.extractRawSelector(i,r);return this.getCssContents(o,new Set([].concat(toConsumableArray(a),toConsumableArray(s))))}},{key:"getCssContents",value:function(t,e){var r=[],o=!0,n=!1,i=void 0;try{for(var a,s=t[Symbol.iterator]();!(o=(a=s.next()).done);o=!0){var l=a.value,u=null,c="";"string"==typeof l?(u=l,c=this.options.stdin?u:fs.readFileSync(u,"utf8")):c=l.raw,this.root=postcss.parse(c),this.getSelectorsCss(e),this.options.keyframes&&this.removeUnusedKeyframes(),r.push({file:u,css:this.root.toString()})}}catch(t){n=!0,i=t}finally{try{!o&&s.return&&s.return()}finally{if(n)throw i}}return r}},{key:"removeUnusedKeyframes",value:function(){var t=new Set;this.root.walkDecls(/animation/,function(e){var r=!0,o=!1,n=void 0;try{for(var i,a=e.value.split(" ")[Symbol.iterator]();!(r=(i=a.next()).done);r=!0){var s=i.value;t.add(s)}}catch(t){o=!0,n=t}finally{try{!r&&a.return&&a.return()}finally{if(o)throw n}}});for(var e in this.atRules.keyframes){t.has(e)||this.atRules.keyframes[e].remove()}}},{key:"extractRawSelector",value:function(t,e){var r=new Set,o=!0,n=!1,i=void 0;try{for(var a,s=t[Symbol.iterator]();!(o=(a=s.next()).done);o=!0){var l=a.value,u=l.raw,c=l.extension,f=this.getFileExtractor("."+c,e);r=new Set([].concat(toConsumableArray(r),toConsumableArray(this.extractSelectors(u,f))))}}catch(t){n=!0,i=t}finally{try{!o&&s.return&&s.return()}finally{if(n)throw i}}return r}},{key:"extractFileSelector",value:function(t,e){var r=new Set,o=!0,n=!1,i=void 0;try{for(var a,s=t[Symbol.iterator]();!(o=(a=s.next()).done);o=!0){var l=a.value,u=[];fs.existsSync(l)?u.push(l):u=glob.sync(l);var c=!0,f=!1,y=void 0;try{for(var p,h=u[Symbol.iterator]();!(c=(p=h.next()).done);c=!0){var v=p.value,E=fs.readFileSync(v,"utf8"),R=this.getFileExtractor(v,e);r=new Set([].concat(toConsumableArray(r),toConsumableArray(this.extractSelectors(E,R))))}}catch(t){f=!0,y=t}finally{try{!c&&h.return&&h.return()}finally{if(f)throw y}}}}catch(t){n=!0,i=t}finally{try{!o&&s.return&&s.return()}finally{if(n)throw i}}return r}},{key:"getFileExtractor",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return e.length?e.find(function(e){return e.extensions.find(function(e){return t.endsWith(e)})}).extractor:!0===this.options.legacy?LegacyExtractor:DefaultExtractor}},{key:"extractSelectors",value:function(t,e){var r=new Set,o=e.extract(t);if(null===o)throw new Error(ERROR_EXTRACTER_FAILED);return o.forEach(function(t){r.add(t)}),r.delete(""),r}},{key:"getSelectorsCss",value:function(t){var e=this;this.root.walkRules(function(r){var o=r.prev();if(!e.isIgnoreAnnotation(o)){r.selector=selectorParser(function(r){r.walk(function(r){var o=[];if("selector"===r.type){if(r.parent&&":not"===r.parent.value&&"pseudo"===r.parent.type)return;var n=!0,i=!1,a=void 0;try{for(var s,l=r.nodes[Symbol.iterator]();!(n=(s=l.next()).done);n=!0){var u=s.value,c=u.type,f=u.value;SELECTOR_STANDARD_TYPES.includes(c)&&void 0!==f?o.push(f):"tag"!==c||/[+]|(even)|(odd)|^from$|^to$|^\d/.test(f)||o.push(f)}}catch(t){i=!0,a=t}finally{try{!n&&l.return&&l.return()}finally{if(i)throw a}}e.shouldKeepSelector(t,o)||r.remove()}})}).processSync(r.selector);var n=r.parent;"atrule"===n.type&&e.options.keyframes&&"keyframes"===n.name&&(e.atRules.keyframes[n.params]=n),r.selector||r.remove(),e.isRuleEmpty(n)&&n.remove()}})}},{key:"isIgnoreAnnotation",value:function(t){return!(!t||"comment"!==t.type)&&t.text.includes(IGNORE_ANNOTATION)}},{key:"isRuleEmpty",value:function(t){return!!("decl"===t.type&&!t.value||"rule"===t.type&&!t.selector||t.nodes&&!t.nodes.length||"atrule"===t.type&&(!t.nodes&&!t.params||!t.params&&!t.nodes.length))}},{key:"shouldKeepSelector",value:function(t,e){var r=!0,o=!1,n=void 0;try{for(var i,a=e[Symbol.iterator]();!(r=(i=a.next()).done);r=!0){var s=i.value;if(this.options.legacy){var l=s.split(/[^a-z]/g),u=!1,c=!0,f=!1,y=void 0;try{for(var p,h=l[Symbol.iterator]();!(c=(p=h.next()).done);c=!0){var v=p.value;if(v){if(!t.has(v))break;u=!0}}}catch(t){f=!0,y=t}finally{try{!c&&h.return&&h.return()}finally{if(f)throw y}}if(u)return!0;if(t.has(s)||CSS_WHITELIST.includes(s)||this.isSelectorWhitelisted(s))return!0}else{var E=s.replace(/\\/g,"");if(E.startsWith(":"))continue;if(!(t.has(E)||CSS_WHITELIST.includes(E)||this.isSelectorWhitelisted(E)))return!1}}}catch(t){o=!0,n=t}finally{try{!r&&a.return&&a.return()}finally{if(o)throw n}}return!this.options.legacy}},{key:"isSelectorWhitelisted",value:function(t){return!!(CSS_WHITELIST.includes(t)||this.options.whitelist&&this.options.whitelist.some(function(e){return e===t})||this.options.whitelistPatterns&&this.options.whitelistPatterns.some(function(e){return e.test(t)}))}}]),t}();export default Purgecss;
import fs from"fs";import glob from"glob";import postcss from"postcss";import selectorParser from"postcss-selector-parser";function normalizeArray(e,t){for(var r=0,n=e.length-1;n>=0;n--){var o=e[n];"."===o?e.splice(n,1):".."===o?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r--;r)e.unshift("..");return e}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,splitPath=function(e){return splitPathRe.exec(e).slice(1)};function resolve(){for(var e="",t=!1,r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if("string"!=typeof n)throw new TypeError("Arguments to path.resolve must be strings");n&&(e=n+"/"+e,t="/"===n.charAt(0))}return e=normalizeArray(filter(e.split("/"),function(e){return!!e}),!t).join("/"),(t?"/":"")+e||"."}function normalize(e){var t=isAbsolute(e),r="/"===substr(e,-1);return(e=normalizeArray(filter(e.split("/"),function(e){return!!e}),!t).join("/"))||t||(e="."),e&&r&&(e+="/"),(t?"/":"")+e}function isAbsolute(e){return"/"===e.charAt(0)}function join(){return normalize(filter(Array.prototype.slice.call(arguments,0),function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))}function relative(e,t){function r(e){for(var t=0;t<e.length&&""===e[t];t++);for(var r=e.length-1;r>=0&&""===e[r];r--);return t>r?[]:e.slice(t,r-t+1)}e=resolve(e).substr(1),t=resolve(t).substr(1);for(var n=r(e.split("/")),o=r(t.split("/")),i=Math.min(n.length,o.length),a=i,s=0;s<i;s++)if(n[s]!==o[s]){a=s;break}var l=[];for(s=a;s<n.length;s++)l.push("..");return(l=l.concat(o.slice(a))).join("/")}var sep="/",delimiter=":";function dirname(e){var t=splitPath(e),r=t[0],n=t[1];return r||n?(n&&(n=n.substr(0,n.length-1)),r+n):"."}function basename(e,t){var r=splitPath(e)[2];return t&&r.substr(-1*t.length)===t&&(r=r.substr(0,r.length-t.length)),r}function extname(e){return splitPath(e)[3]}var path={extname:extname,basename:basename,dirname:dirname,sep:sep,delimiter:delimiter,relative:relative,join:join,isAbsolute:isAbsolute,normalize:normalize,resolve:resolve};function filter(e,t){if(e.filter)return e.filter(t);for(var r=[],n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r}var substr="b"==="ab".substr(-1)?function(e,t,r){return e.substr(t,r)}:function(e,t,r){return t<0&&(t=e.length+t),e.substr(t,r)},defaultOptions={css:[],content:[],extractors:[],whitelist:[],output:void 0,stdout:!1,info:!1,rejected:!1,legacy:!1,keyframes:!1,fontFace:!1},IGNORE_ANNOTATION="purgecss ignore",CONFIG_FILENAME="purgecss.config.js",ERROR_CONFIG_FILE_LOADING="Error loading the config file",ERROR_MISSING_CONTENT="No content provided.",ERROR_MISSING_CSS="No css provided.",ERROR_EXTRACTER_FAILED="The extractor has failed to extract the selectors.",ERROR_OPTIONS_TYPE="Error Type Options: expected an object",ERROR_OUTPUT_TYPE="Error Type option output: expected a string",ERROR_EXTRACTERS_TYPE="Error Type option extractors: expected an array",ERROR_WHITELIST_TYPE="Error Type option whitelist: expected an array",ERROR_WHITELIST_PATTERNS_TYPE="Error Type option whitelistPatterns: expected an array",ERROR_STDOUT_TYPE="Error Type option stdout: expected a boolean",ERROR_INFO_TYPE="Error Type option info: expected a boolean",ERROR_REJECTED_TYPE="Error Type option rejected: expected a boolean",CSS_WHITELIST=["*","::-webkit-scrollbar","::selection",":root","::before","::after"],SELECTOR_STANDARD_TYPES=["class","id","universal","pseudo"],_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},DefaultExtractor=function(){function e(){classCallCheck(this,e)}return createClass(e,null,[{key:"extract",value:function(e){return e.match(/[A-Za-z0-9_-]+/g)}}]),e}(),LegacyExtractor=function(){function e(){classCallCheck(this,e)}return createClass(e,null,[{key:"extract",value:function(e){return e.split(/[^a-z]/g)}}]),e}(),Purgecss=function(){function e(t){classCallCheck(this,e),this.atRules={keyframes:[],fontFace:[]},this.usedAnimations=new Set,this.usedFontFaces=new Set,this.selectorsRemoved=new Set,"string"!=typeof t&&void 0!==t||(t=this.loadConfigFile(t)),this.checkOptions(t),this.options=Object.assign(defaultOptions,t)}return createClass(e,[{key:"loadConfigFile",value:function(e){var t=void 0===e?CONFIG_FILENAME:e,r=void 0;try{var n=path.resolve(process.cwd(),t);r=require(n)}catch(e){throw new Error(ERROR_CONFIG_FILE_LOADING+e.message)}return r}},{key:"checkOptions",value:function(e){if("object"!==(void 0===e?"undefined":_typeof(e)))throw new TypeError(ERROR_OPTIONS_TYPE);if(!e.content||!e.content.length)throw new Error(ERROR_MISSING_CONTENT);if(!e.css||!e.css.length)throw new Error(ERROR_MISSING_CSS);if(e.output&&"string"!=typeof e.output)throw new TypeError(ERROR_OUTPUT_TYPE);if(e.extractors&&!Array.isArray(e.extractors))throw new TypeError(ERROR_EXTRACTERS_TYPE);if(e.whitelist&&!Array.isArray(e.whitelist))throw new TypeError(ERROR_WHITELIST_TYPE);if(e.stdout&&"boolean"!=typeof e.stdout)throw new TypeError(ERROR_STDOUT_TYPE);if(e.info&&"boolean"!=typeof e.info)throw new TypeError(ERROR_INFO_TYPE);if(e.rejected&&"boolean"!=typeof e.rejected)throw new TypeError(ERROR_REJECTED_TYPE);if(e.whitelistPatterns&&!Array.isArray(e.whitelistPatterns))throw new TypeError(ERROR_WHITELIST_PATTERNS_TYPE)}},{key:"purge",value:function(){var e=this.options,t=e.content,r=e.extractors,n=e.css,o=t.filter(function(e){return"string"==typeof e}),i=t.filter(function(e){return"object"===(void 0===e?"undefined":_typeof(e))}),a=this.extractFileSelector(o,r),s=this.extractRawSelector(i,r);return this.getCssContents(n,new Set([].concat(toConsumableArray(a),toConsumableArray(s))))}},{key:"getCssContents",value:function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value,u=null,c="";"string"==typeof l?(u=l,c=this.options.stdin?u:fs.readFileSync(u,"utf8")):c=l.raw,this.root=postcss.parse(c),this.getSelectorsCss(t),this.options.keyframes&&this.removeUnusedKeyframes(),this.options.fontFace&&this.removeUnusedFontFaces(),r.push({file:u,css:this.root.toString()})}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}return r}},{key:"removeUnusedKeyframes",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,o=this.atRules.keyframes[Symbol.iterator]();!(e=(n=o.next()).done);e=!0){var i=n.value,a=i.params;this.usedAnimations.has(a)||i.remove()}}catch(e){t=!0,r=e}finally{try{!e&&o.return&&o.return()}finally{if(t)throw r}}}},{key:"removeUnusedFontFaces",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,o=this.atRules.fontFace[Symbol.iterator]();!(e=(n=o.next()).done);e=!0){var i=n.value,a=i.node,s=i.name;this.usedFontFaces.has(s)||a.remove()}}catch(e){t=!0,r=e}finally{try{!e&&o.return&&o.return()}finally{if(t)throw r}}}},{key:"extractRawSelector",value:function(e,t){var r=new Set,n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value,u=l.raw,c=l.extension,f=this.getFileExtractor("."+c,t);r=new Set([].concat(toConsumableArray(r),toConsumableArray(this.extractSelectors(u,f))))}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}return r}},{key:"extractFileSelector",value:function(e,t){var r=new Set,n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value,u=[];fs.existsSync(l)?u.push(l):u=glob.sync(l);var c=!0,f=!1,y=void 0;try{for(var h,p=u[Symbol.iterator]();!(c=(h=p.next()).done);c=!0){var v=h.value,d=fs.readFileSync(v,"utf8"),E=this.getFileExtractor(v,t);r=new Set([].concat(toConsumableArray(r),toConsumableArray(this.extractSelectors(d,E))))}}catch(e){f=!0,y=e}finally{try{!c&&p.return&&p.return()}finally{if(f)throw y}}}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}return r}},{key:"getFileExtractor",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return t.length?t.find(function(t){return t.extensions.find(function(t){return e.endsWith(t)})}).extractor:!0===this.options.legacy?LegacyExtractor:DefaultExtractor}},{key:"extractSelectors",value:function(e,t){var r=new Set,n=t.extract(e);if(null===n)throw new Error(ERROR_EXTRACTER_FAILED);return n.forEach(function(e){r.add(e)}),r.delete(""),r}},{key:"getSelectorsCss",value:function(e){var t=this;this.root.walk(function(r){return"rule"===r.type?t.evaluateRule(r,e):"atrule"===r.type?t.evaluateAtRule(r):void 0})}},{key:"evaluateRule",value:function(e,t){var r=this,n=e.prev();if(!this.isIgnoreAnnotation(n)){var o=!0;if(e.selector=selectorParser(function(e){e.walk(function(e){var n=[];if("selector"===e.type){if(e.parent&&":not"===e.parent.value&&"pseudo"===e.parent.type)return;var i=!0,a=!1,s=void 0;try{for(var l,u=e.nodes[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var c=l.value,f=c.type,y=c.value;SELECTOR_STANDARD_TYPES.includes(f)&&void 0!==y?n.push(y):"tag"!==f||/[+]|(even)|(odd)|^from$|^to$|^\d/.test(y)||n.push(y)}}catch(e){a=!0,s=e}finally{try{!i&&u.return&&u.return()}finally{if(a)throw s}}(o=r.shouldKeepSelector(t,n))||e.remove()}})}).processSync(e.selector),o){var i=!0,a=!1,s=void 0;try{for(var l,u=e.nodes[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var c=l.value,f=c.prop,y=c.value;if(this.options.keyframes&&("animation"===f||"animation-name"===f)){var h=!0,p=!1,v=void 0;try{for(var d,E=y.split(" ")[Symbol.iterator]();!(h=(d=E.next()).done);h=!0){var R=d.value;this.usedAnimations.add(R)}}catch(e){p=!0,v=e}finally{try{!h&&E.return&&E.return()}finally{if(p)throw v}}}this.options.fontFace&&"font-family"===f&&this.usedFontFaces.add(y)}}catch(e){a=!0,s=e}finally{try{!i&&u.return&&u.return()}finally{if(a)throw s}}}var m=e.parent;e.selector||e.remove(),this.isRuleEmpty(m)&&m.remove()}}},{key:"evaluateAtRule",value:function(e){if(this.options.keyframes&&e.name.endsWith("keyframes"))this.atRules.keyframes.push(e);else if(this.options.fontFace&&"font-face"===e.name){var t=!0,r=!1,n=void 0;try{for(var o,i=e.nodes[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){var a=o.value,s=a.prop,l=a.value;"font-family"===s&&this.atRules.fontFace.push({name:l,node:e})}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}}else;}},{key:"isIgnoreAnnotation",value:function(e){return!(!e||"comment"!==e.type)&&e.text.includes(IGNORE_ANNOTATION)}},{key:"isRuleEmpty",value:function(e){return!!("decl"===e.type&&!e.value||"rule"===e.type&&!e.selector||e.nodes&&!e.nodes.length||"atrule"===e.type&&(!e.nodes&&!e.params||!e.params&&!e.nodes.length))}},{key:"shouldKeepSelector",value:function(e,t){var r=!0,n=!1,o=void 0;try{for(var i,a=t[Symbol.iterator]();!(r=(i=a.next()).done);r=!0){var s=i.value;if(this.options.legacy){var l=s.split(/[^a-z]/g),u=!1,c=!0,f=!1,y=void 0;try{for(var h,p=l[Symbol.iterator]();!(c=(h=p.next()).done);c=!0){var v=h.value;if(v){if(!e.has(v))break;u=!0}}}catch(e){f=!0,y=e}finally{try{!c&&p.return&&p.return()}finally{if(f)throw y}}if(u)return!0;if(e.has(s)||CSS_WHITELIST.includes(s)||this.isSelectorWhitelisted(s))return!0}else{var d=s.replace(/\\/g,"");if(d.startsWith(":"))continue;if(!(e.has(d)||CSS_WHITELIST.includes(d)||this.isSelectorWhitelisted(d)))return!1}}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}return!this.options.legacy}},{key:"isSelectorWhitelisted",value:function(e){return!!(CSS_WHITELIST.includes(e)||this.options.whitelist&&this.options.whitelist.some(function(t){return t===e})||this.options.whitelistPatterns&&this.options.whitelistPatterns.some(function(t){return t.test(e)}))}}]),e}();export default Purgecss;

@@ -1,1 +0,1 @@

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var fs=_interopDefault(require("fs")),glob=_interopDefault(require("glob")),postcss=_interopDefault(require("postcss")),selectorParser=_interopDefault(require("postcss-selector-parser"));function normalizeArray(e,t){for(var r=0,n=e.length-1;n>=0;n--){var o=e[n];"."===o?e.splice(n,1):".."===o?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r--;r)e.unshift("..");return e}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,splitPath=function(e){return splitPathRe.exec(e).slice(1)};function resolve(){for(var e="",t=!1,r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if("string"!=typeof n)throw new TypeError("Arguments to path.resolve must be strings");n&&(e=n+"/"+e,t="/"===n.charAt(0))}return e=normalizeArray(filter(e.split("/"),function(e){return!!e}),!t).join("/"),(t?"/":"")+e||"."}function normalize(e){var t=isAbsolute(e),r="/"===substr(e,-1);return(e=normalizeArray(filter(e.split("/"),function(e){return!!e}),!t).join("/"))||t||(e="."),e&&r&&(e+="/"),(t?"/":"")+e}function isAbsolute(e){return"/"===e.charAt(0)}function join(){return normalize(filter(Array.prototype.slice.call(arguments,0),function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))}function relative(e,t){function r(e){for(var t=0;t<e.length&&""===e[t];t++);for(var r=e.length-1;r>=0&&""===e[r];r--);return t>r?[]:e.slice(t,r-t+1)}e=resolve(e).substr(1),t=resolve(t).substr(1);for(var n=r(e.split("/")),o=r(t.split("/")),i=Math.min(n.length,o.length),a=i,s=0;s<i;s++)if(n[s]!==o[s]){a=s;break}var l=[];for(s=a;s<n.length;s++)l.push("..");return(l=l.concat(o.slice(a))).join("/")}var sep="/",delimiter=":";function dirname(e){var t=splitPath(e),r=t[0],n=t[1];return r||n?(n&&(n=n.substr(0,n.length-1)),r+n):"."}function basename(e,t){var r=splitPath(e)[2];return t&&r.substr(-1*t.length)===t&&(r=r.substr(0,r.length-t.length)),r}function extname(e){return splitPath(e)[3]}var path={extname:extname,basename:basename,dirname:dirname,sep:sep,delimiter:delimiter,relative:relative,join:join,isAbsolute:isAbsolute,normalize:normalize,resolve:resolve};function filter(e,t){if(e.filter)return e.filter(t);for(var r=[],n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r}var substr="b"==="ab".substr(-1)?function(e,t,r){return e.substr(t,r)}:function(e,t,r){return t<0&&(t=e.length+t),e.substr(t,r)},defaultOptions={css:[],content:[],extractors:[],whitelist:[],output:void 0,stdout:!1,info:!1,rejected:!1,legacy:!1,keyframes:!1},IGNORE_ANNOTATION="purgecss ignore",CONFIG_FILENAME="purgecss.config.js",ERROR_CONFIG_FILE_LOADING="Error loading the config file",ERROR_MISSING_CONTENT="No content provided.",ERROR_MISSING_CSS="No css provided.",ERROR_EXTRACTER_FAILED="The extractor has failed to extract the selectors.",ERROR_OPTIONS_TYPE="Error Type Options: expected an object",ERROR_OUTPUT_TYPE="Error Type option output: expected a string",ERROR_EXTRACTERS_TYPE="Error Type option extractors: expected an array",ERROR_WHITELIST_TYPE="Error Type option whitelist: expected an array",ERROR_WHITELIST_PATTERNS_TYPE="Error Type option whitelistPatterns: expected an array",ERROR_STDOUT_TYPE="Error Type option stdout: expected a boolean",ERROR_INFO_TYPE="Error Type option info: expected a boolean",ERROR_REJECTED_TYPE="Error Type option rejected: expected a boolean",CSS_WHITELIST=["*","::-webkit-scrollbar","::selection",":root","::before","::after"],SELECTOR_STANDARD_TYPES=["class","id","universal","pseudo"],_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},DefaultExtractor=function(){function e(){classCallCheck(this,e)}return createClass(e,null,[{key:"extract",value:function(e){return e.match(/[A-Za-z0-9_-]+/g)}}]),e}(),LegacyExtractor=function(){function e(){classCallCheck(this,e)}return createClass(e,null,[{key:"extract",value:function(e){return e.split(/[^a-z]/g)}}]),e}(),Purgecss=function(){function e(t){classCallCheck(this,e),this.atRules={keyframes:{}},"string"!=typeof t&&void 0!==t||(t=this.loadConfigFile(t)),this.checkOptions(t),this.options=Object.assign(defaultOptions,t)}return createClass(e,[{key:"loadConfigFile",value:function(e){var t=void 0===e?CONFIG_FILENAME:e,r=void 0;try{var n=path.resolve(process.cwd(),t);r=require(n)}catch(e){throw new Error(ERROR_CONFIG_FILE_LOADING+e.message)}return r}},{key:"checkOptions",value:function(e){if("object"!==(void 0===e?"undefined":_typeof(e)))throw new TypeError(ERROR_OPTIONS_TYPE);if(!e.content||!e.content.length)throw new Error(ERROR_MISSING_CONTENT);if(!e.css||!e.css.length)throw new Error(ERROR_MISSING_CSS);if(e.output&&"string"!=typeof e.output)throw new TypeError(ERROR_OUTPUT_TYPE);if(e.extractors&&!Array.isArray(e.extractors))throw new TypeError(ERROR_EXTRACTERS_TYPE);if(e.whitelist&&!Array.isArray(e.whitelist))throw new TypeError(ERROR_WHITELIST_TYPE);if(e.stdout&&"boolean"!=typeof e.stdout)throw new TypeError(ERROR_STDOUT_TYPE);if(e.info&&"boolean"!=typeof e.info)throw new TypeError(ERROR_INFO_TYPE);if(e.rejected&&"boolean"!=typeof e.rejected)throw new TypeError(ERROR_REJECTED_TYPE);if(e.whitelistPatterns&&!Array.isArray(e.whitelistPatterns))throw new TypeError(ERROR_WHITELIST_PATTERNS_TYPE)}},{key:"purge",value:function(){var e=this.options,t=e.content,r=e.extractors,n=e.css,o=t.filter(function(e){return"string"==typeof e}),i=t.filter(function(e){return"object"===(void 0===e?"undefined":_typeof(e))}),a=this.extractFileSelector(o,r),s=this.extractRawSelector(i,r);return this.getCssContents(n,new Set([].concat(toConsumableArray(a),toConsumableArray(s))))}},{key:"getCssContents",value:function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value,u=null,c="";"string"==typeof l?(u=l,c=this.options.stdin?u:fs.readFileSync(u,"utf8")):c=l.raw,this.root=postcss.parse(c),this.getSelectorsCss(t),this.options.keyframes&&this.removeUnusedKeyframes(),r.push({file:u,css:this.root.toString()})}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}return r}},{key:"removeUnusedKeyframes",value:function(){var e=new Set;this.root.walkDecls(/animation/,function(t){var r=!0,n=!1,o=void 0;try{for(var i,a=t.value.split(" ")[Symbol.iterator]();!(r=(i=a.next()).done);r=!0){var s=i.value;e.add(s)}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}});for(var t in this.atRules.keyframes){e.has(t)||this.atRules.keyframes[t].remove()}}},{key:"extractRawSelector",value:function(e,t){var r=new Set,n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value,u=l.raw,c=l.extension,f=this.getFileExtractor("."+c,t);r=new Set([].concat(toConsumableArray(r),toConsumableArray(this.extractSelectors(u,f))))}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}return r}},{key:"extractFileSelector",value:function(e,t){var r=new Set,n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value,u=[];fs.existsSync(l)?u.push(l):u=glob.sync(l);var c=!0,f=!1,y=void 0;try{for(var p,h=u[Symbol.iterator]();!(c=(p=h.next()).done);c=!0){var v=p.value,E=fs.readFileSync(v,"utf8"),R=this.getFileExtractor(v,t);r=new Set([].concat(toConsumableArray(r),toConsumableArray(this.extractSelectors(E,R))))}}catch(e){f=!0,y=e}finally{try{!c&&h.return&&h.return()}finally{if(f)throw y}}}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}return r}},{key:"getFileExtractor",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return t.length?t.find(function(t){return t.extensions.find(function(t){return e.endsWith(t)})}).extractor:!0===this.options.legacy?LegacyExtractor:DefaultExtractor}},{key:"extractSelectors",value:function(e,t){var r=new Set,n=t.extract(e);if(null===n)throw new Error(ERROR_EXTRACTER_FAILED);return n.forEach(function(e){r.add(e)}),r.delete(""),r}},{key:"getSelectorsCss",value:function(e){var t=this;this.root.walkRules(function(r){var n=r.prev();if(!t.isIgnoreAnnotation(n)){r.selector=selectorParser(function(r){r.walk(function(r){var n=[];if("selector"===r.type){if(r.parent&&":not"===r.parent.value&&"pseudo"===r.parent.type)return;var o=!0,i=!1,a=void 0;try{for(var s,l=r.nodes[Symbol.iterator]();!(o=(s=l.next()).done);o=!0){var u=s.value,c=u.type,f=u.value;SELECTOR_STANDARD_TYPES.includes(c)&&void 0!==f?n.push(f):"tag"!==c||/[+]|(even)|(odd)|^from$|^to$|^\d/.test(f)||n.push(f)}}catch(e){i=!0,a=e}finally{try{!o&&l.return&&l.return()}finally{if(i)throw a}}t.shouldKeepSelector(e,n)||r.remove()}})}).processSync(r.selector);var o=r.parent;"atrule"===o.type&&t.options.keyframes&&"keyframes"===o.name&&(t.atRules.keyframes[o.params]=o),r.selector||r.remove(),t.isRuleEmpty(o)&&o.remove()}})}},{key:"isIgnoreAnnotation",value:function(e){return!(!e||"comment"!==e.type)&&e.text.includes(IGNORE_ANNOTATION)}},{key:"isRuleEmpty",value:function(e){return!!("decl"===e.type&&!e.value||"rule"===e.type&&!e.selector||e.nodes&&!e.nodes.length||"atrule"===e.type&&(!e.nodes&&!e.params||!e.params&&!e.nodes.length))}},{key:"shouldKeepSelector",value:function(e,t){var r=!0,n=!1,o=void 0;try{for(var i,a=t[Symbol.iterator]();!(r=(i=a.next()).done);r=!0){var s=i.value;if(this.options.legacy){var l=s.split(/[^a-z]/g),u=!1,c=!0,f=!1,y=void 0;try{for(var p,h=l[Symbol.iterator]();!(c=(p=h.next()).done);c=!0){var v=p.value;if(v){if(!e.has(v))break;u=!0}}}catch(e){f=!0,y=e}finally{try{!c&&h.return&&h.return()}finally{if(f)throw y}}if(u)return!0;if(e.has(s)||CSS_WHITELIST.includes(s)||this.isSelectorWhitelisted(s))return!0}else{var E=s.replace(/\\/g,"");if(E.startsWith(":"))continue;if(!(e.has(E)||CSS_WHITELIST.includes(E)||this.isSelectorWhitelisted(E)))return!1}}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}return!this.options.legacy}},{key:"isSelectorWhitelisted",value:function(e){return!!(CSS_WHITELIST.includes(e)||this.options.whitelist&&this.options.whitelist.some(function(t){return t===e})||this.options.whitelistPatterns&&this.options.whitelistPatterns.some(function(t){return t.test(e)}))}}]),e}();module.exports=Purgecss;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var fs=_interopDefault(require("fs")),glob=_interopDefault(require("glob")),postcss=_interopDefault(require("postcss")),selectorParser=_interopDefault(require("postcss-selector-parser"));function normalizeArray(e,t){for(var r=0,n=e.length-1;n>=0;n--){var o=e[n];"."===o?e.splice(n,1):".."===o?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r--;r)e.unshift("..");return e}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,splitPath=function(e){return splitPathRe.exec(e).slice(1)};function resolve(){for(var e="",t=!1,r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if("string"!=typeof n)throw new TypeError("Arguments to path.resolve must be strings");n&&(e=n+"/"+e,t="/"===n.charAt(0))}return e=normalizeArray(filter(e.split("/"),function(e){return!!e}),!t).join("/"),(t?"/":"")+e||"."}function normalize(e){var t=isAbsolute(e),r="/"===substr(e,-1);return(e=normalizeArray(filter(e.split("/"),function(e){return!!e}),!t).join("/"))||t||(e="."),e&&r&&(e+="/"),(t?"/":"")+e}function isAbsolute(e){return"/"===e.charAt(0)}function join(){return normalize(filter(Array.prototype.slice.call(arguments,0),function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))}function relative(e,t){function r(e){for(var t=0;t<e.length&&""===e[t];t++);for(var r=e.length-1;r>=0&&""===e[r];r--);return t>r?[]:e.slice(t,r-t+1)}e=resolve(e).substr(1),t=resolve(t).substr(1);for(var n=r(e.split("/")),o=r(t.split("/")),i=Math.min(n.length,o.length),a=i,s=0;s<i;s++)if(n[s]!==o[s]){a=s;break}var l=[];for(s=a;s<n.length;s++)l.push("..");return(l=l.concat(o.slice(a))).join("/")}var sep="/",delimiter=":";function dirname(e){var t=splitPath(e),r=t[0],n=t[1];return r||n?(n&&(n=n.substr(0,n.length-1)),r+n):"."}function basename(e,t){var r=splitPath(e)[2];return t&&r.substr(-1*t.length)===t&&(r=r.substr(0,r.length-t.length)),r}function extname(e){return splitPath(e)[3]}var path={extname:extname,basename:basename,dirname:dirname,sep:sep,delimiter:delimiter,relative:relative,join:join,isAbsolute:isAbsolute,normalize:normalize,resolve:resolve};function filter(e,t){if(e.filter)return e.filter(t);for(var r=[],n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r}var substr="b"==="ab".substr(-1)?function(e,t,r){return e.substr(t,r)}:function(e,t,r){return t<0&&(t=e.length+t),e.substr(t,r)},defaultOptions={css:[],content:[],extractors:[],whitelist:[],output:void 0,stdout:!1,info:!1,rejected:!1,legacy:!1,keyframes:!1,fontFace:!1},IGNORE_ANNOTATION="purgecss ignore",CONFIG_FILENAME="purgecss.config.js",ERROR_CONFIG_FILE_LOADING="Error loading the config file",ERROR_MISSING_CONTENT="No content provided.",ERROR_MISSING_CSS="No css provided.",ERROR_EXTRACTER_FAILED="The extractor has failed to extract the selectors.",ERROR_OPTIONS_TYPE="Error Type Options: expected an object",ERROR_OUTPUT_TYPE="Error Type option output: expected a string",ERROR_EXTRACTERS_TYPE="Error Type option extractors: expected an array",ERROR_WHITELIST_TYPE="Error Type option whitelist: expected an array",ERROR_WHITELIST_PATTERNS_TYPE="Error Type option whitelistPatterns: expected an array",ERROR_STDOUT_TYPE="Error Type option stdout: expected a boolean",ERROR_INFO_TYPE="Error Type option info: expected a boolean",ERROR_REJECTED_TYPE="Error Type option rejected: expected a boolean",CSS_WHITELIST=["*","::-webkit-scrollbar","::selection",":root","::before","::after"],SELECTOR_STANDARD_TYPES=["class","id","universal","pseudo"],_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},DefaultExtractor=function(){function e(){classCallCheck(this,e)}return createClass(e,null,[{key:"extract",value:function(e){return e.match(/[A-Za-z0-9_-]+/g)}}]),e}(),LegacyExtractor=function(){function e(){classCallCheck(this,e)}return createClass(e,null,[{key:"extract",value:function(e){return e.split(/[^a-z]/g)}}]),e}(),Purgecss=function(){function e(t){classCallCheck(this,e),this.atRules={keyframes:[],fontFace:[]},this.usedAnimations=new Set,this.usedFontFaces=new Set,this.selectorsRemoved=new Set,"string"!=typeof t&&void 0!==t||(t=this.loadConfigFile(t)),this.checkOptions(t),this.options=Object.assign(defaultOptions,t)}return createClass(e,[{key:"loadConfigFile",value:function(e){var t=void 0===e?CONFIG_FILENAME:e,r=void 0;try{var n=path.resolve(process.cwd(),t);r=require(n)}catch(e){throw new Error(ERROR_CONFIG_FILE_LOADING+e.message)}return r}},{key:"checkOptions",value:function(e){if("object"!==(void 0===e?"undefined":_typeof(e)))throw new TypeError(ERROR_OPTIONS_TYPE);if(!e.content||!e.content.length)throw new Error(ERROR_MISSING_CONTENT);if(!e.css||!e.css.length)throw new Error(ERROR_MISSING_CSS);if(e.output&&"string"!=typeof e.output)throw new TypeError(ERROR_OUTPUT_TYPE);if(e.extractors&&!Array.isArray(e.extractors))throw new TypeError(ERROR_EXTRACTERS_TYPE);if(e.whitelist&&!Array.isArray(e.whitelist))throw new TypeError(ERROR_WHITELIST_TYPE);if(e.stdout&&"boolean"!=typeof e.stdout)throw new TypeError(ERROR_STDOUT_TYPE);if(e.info&&"boolean"!=typeof e.info)throw new TypeError(ERROR_INFO_TYPE);if(e.rejected&&"boolean"!=typeof e.rejected)throw new TypeError(ERROR_REJECTED_TYPE);if(e.whitelistPatterns&&!Array.isArray(e.whitelistPatterns))throw new TypeError(ERROR_WHITELIST_PATTERNS_TYPE)}},{key:"purge",value:function(){var e=this.options,t=e.content,r=e.extractors,n=e.css,o=t.filter(function(e){return"string"==typeof e}),i=t.filter(function(e){return"object"===(void 0===e?"undefined":_typeof(e))}),a=this.extractFileSelector(o,r),s=this.extractRawSelector(i,r);return this.getCssContents(n,new Set([].concat(toConsumableArray(a),toConsumableArray(s))))}},{key:"getCssContents",value:function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value,u=null,c="";"string"==typeof l?(u=l,c=this.options.stdin?u:fs.readFileSync(u,"utf8")):c=l.raw,this.root=postcss.parse(c),this.getSelectorsCss(t),this.options.keyframes&&this.removeUnusedKeyframes(),this.options.fontFace&&this.removeUnusedFontFaces(),r.push({file:u,css:this.root.toString()})}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}return r}},{key:"removeUnusedKeyframes",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,o=this.atRules.keyframes[Symbol.iterator]();!(e=(n=o.next()).done);e=!0){var i=n.value,a=i.params;this.usedAnimations.has(a)||i.remove()}}catch(e){t=!0,r=e}finally{try{!e&&o.return&&o.return()}finally{if(t)throw r}}}},{key:"removeUnusedFontFaces",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,o=this.atRules.fontFace[Symbol.iterator]();!(e=(n=o.next()).done);e=!0){var i=n.value,a=i.node,s=i.name;this.usedFontFaces.has(s)||a.remove()}}catch(e){t=!0,r=e}finally{try{!e&&o.return&&o.return()}finally{if(t)throw r}}}},{key:"extractRawSelector",value:function(e,t){var r=new Set,n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value,u=l.raw,c=l.extension,f=this.getFileExtractor("."+c,t);r=new Set([].concat(toConsumableArray(r),toConsumableArray(this.extractSelectors(u,f))))}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}return r}},{key:"extractFileSelector",value:function(e,t){var r=new Set,n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value,u=[];fs.existsSync(l)?u.push(l):u=glob.sync(l);var c=!0,f=!1,y=void 0;try{for(var h,p=u[Symbol.iterator]();!(c=(h=p.next()).done);c=!0){var v=h.value,d=fs.readFileSync(v,"utf8"),E=this.getFileExtractor(v,t);r=new Set([].concat(toConsumableArray(r),toConsumableArray(this.extractSelectors(d,E))))}}catch(e){f=!0,y=e}finally{try{!c&&p.return&&p.return()}finally{if(f)throw y}}}}catch(e){o=!0,i=e}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}return r}},{key:"getFileExtractor",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return t.length?t.find(function(t){return t.extensions.find(function(t){return e.endsWith(t)})}).extractor:!0===this.options.legacy?LegacyExtractor:DefaultExtractor}},{key:"extractSelectors",value:function(e,t){var r=new Set,n=t.extract(e);if(null===n)throw new Error(ERROR_EXTRACTER_FAILED);return n.forEach(function(e){r.add(e)}),r.delete(""),r}},{key:"getSelectorsCss",value:function(e){var t=this;this.root.walk(function(r){return"rule"===r.type?t.evaluateRule(r,e):"atrule"===r.type?t.evaluateAtRule(r):void 0})}},{key:"evaluateRule",value:function(e,t){var r=this,n=e.prev();if(!this.isIgnoreAnnotation(n)){var o=!0;if(e.selector=selectorParser(function(e){e.walk(function(e){var n=[];if("selector"===e.type){if(e.parent&&":not"===e.parent.value&&"pseudo"===e.parent.type)return;var i=!0,a=!1,s=void 0;try{for(var l,u=e.nodes[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var c=l.value,f=c.type,y=c.value;SELECTOR_STANDARD_TYPES.includes(f)&&void 0!==y?n.push(y):"tag"!==f||/[+]|(even)|(odd)|^from$|^to$|^\d/.test(y)||n.push(y)}}catch(e){a=!0,s=e}finally{try{!i&&u.return&&u.return()}finally{if(a)throw s}}(o=r.shouldKeepSelector(t,n))||e.remove()}})}).processSync(e.selector),o){var i=!0,a=!1,s=void 0;try{for(var l,u=e.nodes[Symbol.iterator]();!(i=(l=u.next()).done);i=!0){var c=l.value,f=c.prop,y=c.value;if(this.options.keyframes&&("animation"===f||"animation-name"===f)){var h=!0,p=!1,v=void 0;try{for(var d,E=y.split(" ")[Symbol.iterator]();!(h=(d=E.next()).done);h=!0){var R=d.value;this.usedAnimations.add(R)}}catch(e){p=!0,v=e}finally{try{!h&&E.return&&E.return()}finally{if(p)throw v}}}this.options.fontFace&&"font-family"===f&&this.usedFontFaces.add(y)}}catch(e){a=!0,s=e}finally{try{!i&&u.return&&u.return()}finally{if(a)throw s}}}var m=e.parent;e.selector||e.remove(),this.isRuleEmpty(m)&&m.remove()}}},{key:"evaluateAtRule",value:function(e){if(this.options.keyframes&&e.name.endsWith("keyframes"))this.atRules.keyframes.push(e);else if(this.options.fontFace&&"font-face"===e.name){var t=!0,r=!1,n=void 0;try{for(var o,i=e.nodes[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){var a=o.value,s=a.prop,l=a.value;"font-family"===s&&this.atRules.fontFace.push({name:l,node:e})}}catch(e){r=!0,n=e}finally{try{!t&&i.return&&i.return()}finally{if(r)throw n}}}else;}},{key:"isIgnoreAnnotation",value:function(e){return!(!e||"comment"!==e.type)&&e.text.includes(IGNORE_ANNOTATION)}},{key:"isRuleEmpty",value:function(e){return!!("decl"===e.type&&!e.value||"rule"===e.type&&!e.selector||e.nodes&&!e.nodes.length||"atrule"===e.type&&(!e.nodes&&!e.params||!e.params&&!e.nodes.length))}},{key:"shouldKeepSelector",value:function(e,t){var r=!0,n=!1,o=void 0;try{for(var i,a=t[Symbol.iterator]();!(r=(i=a.next()).done);r=!0){var s=i.value;if(this.options.legacy){var l=s.split(/[^a-z]/g),u=!1,c=!0,f=!1,y=void 0;try{for(var h,p=l[Symbol.iterator]();!(c=(h=p.next()).done);c=!0){var v=h.value;if(v){if(!e.has(v))break;u=!0}}}catch(e){f=!0,y=e}finally{try{!c&&p.return&&p.return()}finally{if(f)throw y}}if(u)return!0;if(e.has(s)||CSS_WHITELIST.includes(s)||this.isSelectorWhitelisted(s))return!0}else{var d=s.replace(/\\/g,"");if(d.startsWith(":"))continue;if(!(e.has(d)||CSS_WHITELIST.includes(d)||this.isSelectorWhitelisted(d)))return!1}}}catch(e){n=!0,o=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw o}}return!this.options.legacy}},{key:"isSelectorWhitelisted",value:function(e){return!!(CSS_WHITELIST.includes(e)||this.options.whitelist&&this.options.whitelist.some(function(t){return t===e})||this.options.whitelistPatterns&&this.options.whitelistPatterns.some(function(t){return t.test(e)}))}}]),e}();module.exports=Purgecss;
{
"name": "purgecss",
"version": "0.19.0",
"version": "0.20.0",
"description": "Remove unused css selectors.",

@@ -12,4 +12,3 @@ "main": "./lib/purgecss.js",

"test": "__tests__",
"example": "examples",
"doc": "docs"
"example": "examples"
},

@@ -23,3 +22,3 @@ "files": [

"scripts": {
"test": "npx jest .+.test.js",
"test": "npx jest __tests__/.+.test.js",
"dev": "rollup -c rollup.config.js -w",

@@ -54,3 +53,3 @@ "build": "rollup -c rollup.config.js",

"postcss-selector-parser": "^3.1.1",
"yargs": "^10.1.1"
"yargs": "^11.0.0"
},

@@ -64,9 +63,9 @@ "devDependencies": {

"codacy-coverage": "^2.0.3",
"eslint": "^4.15.0",
"eslint-plugin-flowtype": "^2.41.0",
"flow-bin": "^0.63.1",
"jest": "^22.0.6",
"eslint": "^4.16.0",
"eslint-plugin-flowtype": "^2.42.0",
"flow-bin": "^0.64.0",
"jest": "^22.1.4",
"prettier": "^1.10.2",
"regenerator-runtime": "^0.11.1",
"rollup": "^0.54.0",
"rollup": "^0.55.1",
"rollup-plugin-babel": "^3.0.3",

@@ -76,5 +75,4 @@ "rollup-plugin-flow": "^1.1.1",

"rollup-plugin-node-resolve": "^3.0.2",
"rollup-plugin-uglify": "^2.0.1",
"rollup-watch": "^4.3.1",
"uglify-es": "^3.3.7"
"rollup-plugin-uglify": "^3.0.0",
"rollup-watch": "^4.3.1"
},

@@ -81,0 +79,0 @@ "engines": {

@@ -66,3 +66,3 @@ # Purgecss

import Purgecss from 'purgecss'
import purgeHtml from 'purge-from-html'
import purgeHtml from 'purgecss-from-html'
const purgeCss = new Purgecss({

@@ -69,0 +69,0 @@ content: ['**/*.html'],

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc