New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cssjoin

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cssjoin - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

21

lib/cssjoin.js

@@ -45,3 +45,3 @@ var inutil = require("./util.js");

var _this = this;
this.parseCss(this.baseFile, function(err, file){
this.parseCss(this.baseFile, function(err, file){
var css = _this.cssContent[file];

@@ -78,2 +78,12 @@ css = _this.extend(css,file);

CssJoin.prototype.resolveResources = function(css, resolvePaths){
var relativeBase = path.dirname(this.baseFile)
var urlMap = inutil.getUrlMap(css, resolvePaths, relativeBase)
for(var pattern in urlMap) {
css = css.replace(pattern, urlMap[pattern]);
}
return css
}
CssJoin.prototype.parseCss = function(cssFilePath, callback) {

@@ -84,3 +94,5 @@ if(this.cssContent[cssFilePath] && this.replaceMap[cssFilePath]){

}
var _resolvePaths = this.getPaths(cssFilePath);
var _this = this;

@@ -94,2 +106,6 @@ fs.stat(cssFilePath, function(err, result){

var _replaceMap = inutil.getReplaceMap(css, _resolvePaths);
// resolve resouce's url()
css = _this.resolveResources(css, _resolvePaths);
// save css content
_this.cssContent[cssFilePath] = css;

@@ -99,2 +115,4 @@ _this.replaceMap[cssFilePath] = _replaceMap;

var length = Object.keys(_replaceMap).length;
// return if without children
if(length === 0){

@@ -104,2 +122,3 @@ callback(err, cssFilePath, {});

}
// recursive children

@@ -106,0 +125,0 @@ var children = length;

@@ -5,3 +5,2 @@ var fs = require("fs");

var IMPORT_REGEXP = /@import\s.+;/g;

@@ -67,2 +66,4 @@ /**

function getReplaceMap(css, resolvePaths){
var IMPORT_REGEXP = /@import\s.+;/g;
var _replaceMap = {};

@@ -72,3 +73,3 @@

css = removeComments(css);
// get import sytax;

@@ -95,2 +96,26 @@ var importMatches = css.match(IMPORT_REGEXP);

function getUrlMap(css, resolvePaths, relativeBase) {
var URL_REGEXP = /url\(.*?\)/g;
var urlMap = {};
var urlMatches = css.match(URL_REGEXP);
if(urlMatches === null){
return urlMap;
}
for(var i=0; i < urlMatches.length; i++ ){
var urlSyntax = urlMatches[i];
var fileName = findImportFile(urlSyntax)
if(/\.css$/.test(fileName) !== false){
continue;
}
var file = resolvePath(fileName, resolvePaths);
if(!file){
continue;
}
var relativePath = path.relative(relativeBase, file).replace(/\\/g, '/');
urlMap[urlSyntax] = 'url("'+relativePath+'")';
}
return urlMap;
}
module.exports = {

@@ -100,2 +125,3 @@ _resolvePath : resolvePath,

getReplaceMap : getReplaceMap,
getUrlMap : getUrlMap,
getReplaceMapByFile : function(cssFilePath, resolvePaths, cb){

@@ -102,0 +128,0 @@ var _this = this;

2

package.json
{
"name": "cssjoin",
"version": "0.2.1",
"version": "0.3.0",
"description": "Extend css @import loaded file",

@@ -5,0 +5,0 @@ "main": "index.js",

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