@rpl/badge-up
Advanced tools
Comparing version 2.2.0 to 3.0.0
20
index.js
@@ -6,7 +6,5 @@ /* | ||
/* jshint unused:false */ | ||
var fs = require('fs'), | ||
path = require('path'), | ||
SVGO = require('svgo'), | ||
svgo = new SVGO(), | ||
svgo = require('svgo'), | ||
dot = require('dot'), | ||
@@ -42,5 +40,15 @@ template = dot.template(fs.readFileSync(path.join(__dirname, 'templates', 'basic.svg'), 'utf-8')), | ||
// Run the SVG through SVGO. | ||
svgo.optimize(template(data)).then(function (object) { | ||
callback(null, object.data); | ||
}).catch(callback); | ||
const raw = utils.fixupNumericEntities(template(data)); | ||
const optimized = svgo.optimize(raw, { | ||
plugins: ['preset-default'], | ||
}); | ||
if (optimized.modernError) { | ||
if (callback) { | ||
callback(optimized.modernError, undefined); | ||
return; | ||
} | ||
return Promise.reject(optimized.modernError); | ||
} | ||
if (callback) callback(null, optimized.data); | ||
return Promise.resolve(optimized.data); | ||
}; | ||
@@ -47,0 +55,0 @@ |
{ | ||
"name": "@rpl/badge-up", | ||
"version": "2.2.0", | ||
"description": "A module that produces hot badges without the need of Cairo (forked from the original badge-up package to update vulnerable npm deps)", | ||
"version": "3.0.0", | ||
"description": "A module that produces hot badges without the need of Cairo", | ||
"main": "index.js", | ||
"nyc": { | ||
"reporter": [ | ||
"lcov", | ||
"text" | ||
] | ||
}, | ||
"scripts": { | ||
"lint": "jshint *.js test/*.js", | ||
"test": "jenkins-mocha" | ||
"lint": "eslint .", | ||
"test": "nyc --report-dir ./artifacts/coverage mocha --color true", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
@@ -14,5 +21,10 @@ "repository": { | ||
}, | ||
"bugs": "https://github.com/yahoo/badge-up/issues", | ||
"homepage": "https://github.com/rpl/badge-up", | ||
"engines": { | ||
"node": ">=10.0.0" | ||
}, | ||
"bugs": "https://github.com/rpl/badge-up/issues", | ||
"keywords": [ | ||
"badge" | ||
"badge", | ||
"yahoo" | ||
], | ||
@@ -28,17 +40,21 @@ "license": "BSD-3-Clause", | ||
], | ||
"jshintConfig": { | ||
"node": true | ||
"release": { | ||
"debug": false, | ||
"verifyConditions": { | ||
"path": "./node_modules/semantic-release/src/lib/plugin-noop.js" | ||
} | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"coveralls": "^3.0.2", | ||
"jenkins-mocha": "^6.0.0", | ||
"jshint": "^2.9.2", | ||
"sinon": "^1.17.7" | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.11", | ||
"eslint": "^6.8.0", | ||
"mocha": "^7.1.1", | ||
"nyc": "^15.0.0", | ||
"sinon": "^9.0.1" | ||
}, | ||
"dependencies": { | ||
"css-color-names": "~0.0.3", | ||
"dot": "^1.1.1", | ||
"svgo": "^1.1.1" | ||
"css-color-names": "~1.0.1", | ||
"dot": "^1.1.3", | ||
"svgo": "2.6.0" | ||
} | ||
} |
@@ -1,10 +0,1 @@ | ||
# This is a forked version of the original [badge-up npm package](https://www.npmjs.com/package/badge-up) | ||
The only changes applied to the original npm package are: | ||
- updated npm dependencies (to fix some known vulnerabilities detected by npm audit) | ||
- adapt sources to the changes introduced in the new `svgo` library | ||
------ | ||
# badge-up | ||
@@ -28,3 +19,3 @@ | ||
```js | ||
var badge = require('badge-up'); | ||
const badge = require('badge-up'); | ||
badge('batman', 'component', badge.colors.green, function (error, svg) { | ||
@@ -40,3 +31,15 @@ // some callback | ||
You can alternatively use the returned `Promise`: | ||
```js | ||
const badge = require('badge-up'); | ||
(async () => { | ||
try { | ||
const svg = await badge('batman', 'component', badge.colors.green); | ||
} catch (error) { | ||
// | ||
} | ||
}()); | ||
``` | ||
## V2 Usage | ||
@@ -63,9 +66,9 @@ | ||
```js | ||
var badge = require('badge-up'); | ||
var sections = [ | ||
'foo/far;fun', | ||
[ 'bar\nbaz', 'orange'], | ||
[ 'mork "mindy"', 'olive', 's{white}'], | ||
[ '<∀>', 'moccasin'] | ||
]; | ||
const badge = require('badge-up'); | ||
const sections = [ | ||
'foo/far;fun', | ||
[ 'bar\nbaz', 'orange'], | ||
[ 'mork "mindy"', 'olive', 's{white}'], | ||
[ '<∀>', 'moccasin'] | ||
]; | ||
badge.v2(sections, function (error, svg) { | ||
@@ -77,1 +80,21 @@ // some callback | ||
Produces: ![example](https://cdn.rawgit.com/yahoo/badge-up/master/test/testData/v2-example.svg) | ||
You can also use the returned `Promise`: | ||
```js | ||
const badge = require('badge-up'); | ||
const sections = [ | ||
'foo/far;fun', | ||
[ 'bar\nbaz', 'orange'], | ||
[ 'mork "mindy"', 'olive', 's{white}'], | ||
[ '<∀>', 'moccasin'] | ||
]; | ||
(async () => { | ||
try { | ||
const svg = await badge.v2(sections); | ||
} catch (error) { | ||
// | ||
} | ||
}()); | ||
``` |
13
utils.js
@@ -17,4 +17,15 @@ /* | ||
]; | ||
/** | ||
* Replace numeric entity codes with the related entity code name | ||
* for the "<" and "&" characters. Prevent svgo "Unencoded ..." errors, | ||
* see https://github.com/svg/svgo/issues/1498. | ||
* @method replaceNumericEntities | ||
* @param {String} string Input string | ||
* @return {String} Fixed string | ||
*/ | ||
module.exports.fixupNumericEntities = function replaceNumericEntitities(string) { | ||
return string.replace(/&#(x3c|60);/gi, '<') | ||
.replace(/&#(x26|38);/gi, '&'); | ||
} | ||
/** | ||
@@ -21,0 +32,0 @@ * Escape the string so that it doesn't break xml |
32
v2.js
@@ -10,6 +10,4 @@ /* | ||
path = require('path'), | ||
utils = require('./utils'), | ||
svgo = require('svgo'), | ||
utils = require('./utils'), | ||
SVGO = require('svgo'), | ||
svgo = new SVGO(), | ||
TEMPLATE = dot.template(fs.readFileSync(path.join(__dirname, 'templates', 'v2.svg'), 'utf-8')), | ||
@@ -102,6 +100,26 @@ COLOR_REGEX = /^[0-9a-f]{6}$/i, | ||
module.exports = function badge_v2(sections, callback) { | ||
var raw = TEMPLATE(sectionsToData(sections)); | ||
svgo.optimize(raw).then(function(optimized) { | ||
callback(undefined, optimized.data); | ||
}).catch(callback); | ||
var raw = utils.fixupNumericEntities( | ||
TEMPLATE(sectionsToData(sections)) | ||
); | ||
const optimized = svgo.optimize(raw, { | ||
plugins: [ | ||
{ | ||
name: 'preset-default', | ||
params: { | ||
overrides: { | ||
sortDefsChildren: false, | ||
} | ||
} | ||
} | ||
], | ||
}) | ||
if (optimized.modernError) { | ||
if (callback) { | ||
callback(optimized.modernError, undefined); | ||
return; | ||
} | ||
return Promise.reject(optimized.modernError); | ||
} | ||
if (callback) callback(undefined, optimized.data); | ||
return Promise.resolve(optimized.data); | ||
}; | ||
@@ -108,0 +126,0 @@ |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
17882
11
269
0
97
6
+ Added@trysound/sax@0.2.0(transitive)
+ Addedcolorette@1.4.0(transitive)
+ Addedcommander@7.2.0(transitive)
+ Addedcss-color-names@1.0.1(transitive)
+ Addedcss-select@4.3.0(transitive)
+ Addedcss-what@6.1.0(transitive)
+ Addeddom-serializer@1.4.1(transitive)
+ Addeddomhandler@4.3.1(transitive)
+ Addeddomutils@2.8.0(transitive)
+ Addednth-check@2.1.1(transitive)
+ Addedsvgo@2.6.0(transitive)
- Removed@types/q@1.5.8(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedargparse@1.0.10(transitive)
- Removedarray-buffer-byte-length@1.0.2(transitive)
- Removedarray.prototype.reduce@1.0.7(transitive)
- Removedarraybuffer.prototype.slice@1.0.4(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedcall-bind@1.0.8(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcoa@2.0.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcss-color-names@0.0.4(transitive)
- Removedcss-select@2.1.0(transitive)
- Removedcss-select-base-adapter@0.1.1(transitive)
- Removedcss-tree@1.0.0-alpha.37(transitive)
- Removedcss-what@3.4.2(transitive)
- Removeddata-view-buffer@1.0.2(transitive)
- Removeddata-view-byte-length@1.0.2(transitive)
- Removeddata-view-byte-offset@1.0.1(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddom-serializer@0.2.2(transitive)
- Removeddomelementtype@1.3.1(transitive)
- Removeddomutils@1.7.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-abstract@1.23.7(transitive)
- Removedes-array-method-boxes-properly@1.0.0(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedes-set-tostringtag@2.0.3(transitive)
- Removedes-to-primitive@1.3.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedesprima@4.0.1(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfunction.prototype.name@1.1.8(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedget-intrinsic@1.2.6(transitive)
- Removedget-symbol-description@1.1.0(transitive)
- Removedglobalthis@1.0.4(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-bigints@1.1.0(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinternal-slot@1.1.0(transitive)
- Removedis-array-buffer@3.0.5(transitive)
- Removedis-async-function@2.0.0(transitive)
- Removedis-bigint@1.1.0(transitive)
- Removedis-boolean-object@1.2.1(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-data-view@1.0.2(transitive)
- Removedis-date-object@1.1.0(transitive)
- Removedis-finalizationregistry@1.1.1(transitive)
- Removedis-generator-function@1.0.10(transitive)
- Removedis-map@2.0.3(transitive)
- Removedis-number-object@1.1.1(transitive)
- Removedis-regex@1.2.1(transitive)
- Removedis-set@2.0.3(transitive)
- Removedis-shared-array-buffer@1.0.4(transitive)
- Removedis-string@1.1.1(transitive)
- Removedis-symbol@1.1.1(transitive)
- Removedis-typed-array@1.1.15(transitive)
- Removedis-weakmap@2.0.2(transitive)
- Removedis-weakref@1.1.0(transitive)
- Removedis-weakset@2.0.4(transitive)
- Removedisarray@2.0.5(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmdn-data@2.0.4(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednth-check@1.0.2(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.7(transitive)
- Removedobject.getownpropertydescriptors@2.1.8(transitive)
- Removedobject.values@1.2.1(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedq@1.5.1(transitive)
- Removedreflect.getprototypeof@1.0.9(transitive)
- Removedregexp.prototype.flags@1.5.3(transitive)
- Removedsafe-array-concat@1.1.3(transitive)
- Removedsafe-regex-test@1.1.0(transitive)
- Removedsax@1.2.4(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedset-function-name@2.0.2(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstring.prototype.trim@1.2.10(transitive)
- Removedstring.prototype.trimend@1.0.9(transitive)
- Removedstring.prototype.trimstart@1.0.8(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedsvgo@1.3.2(transitive)
- Removedtyped-array-buffer@1.0.3(transitive)
- Removedtyped-array-byte-length@1.0.3(transitive)
- Removedtyped-array-byte-offset@1.0.4(transitive)
- Removedtyped-array-length@1.0.7(transitive)
- Removedunbox-primitive@1.1.0(transitive)
- Removedunquote@1.1.1(transitive)
- Removedutil.promisify@1.0.1(transitive)
- Removedwhich-boxed-primitive@1.1.1(transitive)
- Removedwhich-builtin-type@1.2.1(transitive)
- Removedwhich-collection@1.0.2(transitive)
- Removedwhich-typed-array@1.1.18(transitive)
Updatedcss-color-names@~1.0.1
Updateddot@^1.1.3
Updatedsvgo@2.6.0