Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
absolutize-css-resources
Advanced tools
Convert css images and other resources into absolute paths
Converts the links of all css images, fonts and other resources into absolute paths from a css file, and you are free to worry about improper replacement.
$ npm install absolutize-css-resources --save
var absolutize = require('absolutize-css-resources');
var url = require('url');
absolutize(file_content, {
filename: '/path/to/style.css',
filebase: '/path',
resolve: function(path){
return url.resolve('http://mydomain.com/static/', path);
}
}, function(err, parsed_content){
parsed_content;
});
body {
background: url(img/pic.png)
}
Then the parsed_content
will be:
body {
background: url(http://mydomain.com/static/to/img/pic.png)
}
String
the content of the css fileObject
path
the absolute path of the css filepath
function(relative_path)
the method to resolve the relative_path
to an absolute url
filebase
Boolean=true
whether allow absolute url of css images, such as background: url(/a.png)
which is a bad practice.function()
the error(if exists) and the parsed content will pass to the callback function.function(path, relative_path)=
called if a css resource is found. Optional.
filebase
options.resolve
can be a synchronous method or an asynchronous one by using the common this.async()
style.
Sometimes, we need to invoke an asynchronous process to fetch the version info of a image, querying version from db or digesting md5 from the file content, for example.
// options
{
resolve: function(relative_path){
// Turns the method into an async method
var done = this.async();
my_method_2_get_md5(relative_path, function(err, md5){
if (err) {
return done(err);
}
var REGEX_EXTENSION = /\.[a-z0-9]$/i;
// Inserts md5 string into the path
relative_path = relative_path.replace(REGEX_EXTENSION, function(match){
return '-' + md5.slice(0, 7) + match;
});
// Converts the relative path into an url,
// The converted url might be something like:
// -> http://mydomain.com/static/to/pic-9f9dd65.png
var resolved = require('url').resolve('http://mydomain.com/static/', relative_path);
done(null, resolved);
});
}
}
MIT
FAQs
Convert css images and other resources into absolute paths
The npm package absolutize-css-resources receives a total of 2 weekly downloads. As such, absolutize-css-resources popularity was classified as not popular.
We found that absolutize-css-resources demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.