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

postcss-fontpath

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-fontpath - npm Package Compare versions

Comparing version

to
0.3.0

37

index.js
'use strict';
var fs = require('fs');
var objectAssign = require('object-assign');
var path = require('path');
var postcss = require('postcss');
var url = require('url');
module.exports = postcss.plugin('postcss-fontpath', function () {
return function (css) {
module.exports = postcss.plugin('postcss-fontpath', function (opts) {
opts = objectAssign({
checkPath: false
}, opts);
return function (css, result) {
// Loop through each @rule

@@ -28,2 +36,16 @@ css.walkAtRules('font-face', function(rule) {

if (opts.checkPath === true) {
// Make the fontPath absolute and normalize it (removes the #iefix hash)
var absoluteFontPath = url.parse(path.resolve(path.dirname(css.source.input.file), fontPath) + format.ext).pathname;
try {
fs.accessSync(absoluteFontPath, fs.F_OK);
} catch (err) {
decl.warn(result, 'Cannot find file "' + fontPath + format.ext + '"');
// Skip the format in the src output
return;
}
}
if (index === array.length - 1){

@@ -37,8 +59,11 @@ src += 'url("' + fontPath + format.ext + '") format(\'' + format.type + '\')';

// IE Fix src prop
decl.cloneBefore({ prop: 'src', value: ieSrc });
if (src.length > 0) {
// New src prop
decl.cloneBefore({ prop: 'src', value: src });
// IE Fix src prop
decl.cloneBefore({ prop: 'src', value: ieSrc });
// New src prop
decl.cloneBefore({ prop: 'src', value: src });
}
// Remove our custom decleration

@@ -45,0 +70,0 @@ decl.remove();

3

package.json
{
"name": "postcss-fontpath",
"version": "0.2.0",
"version": "0.3.0",
"description": "PostCSS plugin that adds a font-path attribute to @font-face which expands to the FontSpring syntax",

@@ -29,2 +29,3 @@ "keywords": [

"dependencies": {
"object-assign": "^4.0.1",
"postcss": "^5.0.0"

@@ -31,0 +32,0 @@ },

@@ -43,2 +43,10 @@ # PostCSS FontPath

### Options
**checkPath** (boolean, default = `false`)
If true, the plugin will check if the path to the font file exists. When not found, the file is skipped in the output and a warning is logged.
--
### License

@@ -45,0 +53,0 @@