classless-js
Advanced tools
Comparing version 0.1.5 to 0.1.6
const glob = require('glob'); | ||
const request = require('sync-request'); | ||
const fs = require('fs'); | ||
function getClassesAndIds(stylesheet) { | ||
const classes = []; | ||
const ids = []; | ||
const elemArray = []; | ||
let temp; | ||
// Get the classes | ||
temp = stylesheet.match(/\.\D\w+/g); | ||
// Get the classes and id's | ||
temp = stylesheet.match(/[\.|#]\w+([-]?(-|--)?\w+((-|--)\w+)?)?/g); | ||
if (temp) { | ||
classes.push.apply(classes, temp); | ||
elemArray.push.apply(elemArray, temp); | ||
} | ||
// Get the IDs | ||
temp = stylesheet.match(/\#\D\w+/g); | ||
if (temp) { | ||
ids.push.apply(ids, temp); | ||
} | ||
// Combine classes and ID's and filter for unique ones | ||
const filteredElems = classes.concat(ids) | ||
.filter((v, i, a) => a.indexOf(v) === i); | ||
const filteredElems = elemArray.filter((v, i, a) => a.indexOf(v) === i); | ||
// Return all of the unique elements | ||
// console.log(filteredElems); | ||
return filteredElems; | ||
} | ||
function getAllCSSElems(cssFilePath) { | ||
function getAllCSSElems(cssPathInput) { | ||
//If the CSS file is a url, read the URL and get classes + ids | ||
if (cssFilePath.includes('http')) { | ||
let cssText = getCSSTextFromURL(cssFilePath); | ||
if (cssPathInput.includes('http')) { | ||
let cssText = getCSSTextFromURL(cssPathInput); | ||
return (getClassesAndIds(cssText)); | ||
@@ -41,3 +33,5 @@ } | ||
let eachCSSElemArray = []; | ||
const files = new glob(cssFilePath, {sync: true}); | ||
const files = new glob(cssPathInput, {sync: true}); | ||
const cssFilePath = cssPathInput.substr(0, cssPathInput.indexOf(',')); | ||
// console.log(cssFilePath); | ||
@@ -44,0 +38,0 @@ files.forEach(file => { |
@@ -27,9 +27,15 @@ const glob = require('glob'); | ||
substring.forEach(item => { | ||
// get all id elements and add '#' to all Elem list | ||
if (elem.startsWith("id")) { | ||
allElems.push('#' + item); | ||
// This is for frameworks | ||
if (item.includes("{") || item.includes("}") || item.includes("(") || item.includes(")") || item.includes("/")) { | ||
console.log(item); | ||
return | ||
} else { | ||
// get all id elements and add '#' to all Elem list | ||
if (elem.startsWith("id")) { | ||
allElems.push('#' + item); | ||
// get all class elements and add '.' to all Elem list | ||
} else { | ||
allElems.push('.' + item) | ||
// get all class elements and add '.' to all Elem list | ||
} else { | ||
allElems.push('.' + item) | ||
} | ||
} | ||
@@ -36,0 +42,0 @@ }) |
@@ -23,2 +23,10 @@ #!/usr/bin/env node | ||
fs.writeFile('tmp.txt', cssElemArray, function(err) { | ||
if(err) { | ||
return console.log(err); | ||
} | ||
console.log("The file was saved!"); | ||
}); | ||
// get all of the HTML elements used | ||
@@ -25,0 +33,0 @@ const totalHTMLElemArray = htmlUtils.getAllHTMLElems(htmlFilePath); |
{ | ||
"name": "classless-js", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Enforce and question your design system by checking your classes against an approved class list", | ||
@@ -5,0 +5,0 @@ "main": "bin/index.js", |
@@ -30,1 +30,2 @@ # Classless.js | ||
- CSS as local or URL link | ||
- Ember plugin |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9144
12
170
31
3