Comparing version 2.3.0 to 2.4.0
@@ -41,4 +41,5 @@ /* | ||
// Run the SVG through SVGO. | ||
svgo.optimize(template(data), function (object) { | ||
callback(null, object.data); | ||
return svgo.optimize(template(data)).then(function (object) { | ||
if (callback) callback(null, object.data); | ||
return object.data; | ||
}); | ||
@@ -45,0 +46,0 @@ }; |
{ | ||
"name": "badge-up", | ||
"version": "2.3.0", | ||
"version": "2.4.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" | ||
"test": "nyc --report-dir ./artifacts/coverage mocha --color true", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
@@ -16,3 +23,4 @@ "repository": { | ||
"keywords": [ | ||
"badge" | ||
"badge", | ||
"yahoo" | ||
], | ||
@@ -28,2 +36,8 @@ "license": "BSD-3-Clause", | ||
], | ||
"release": { | ||
"debug": false, | ||
"verifyConditions": { | ||
"path": "./node_modules/semantic-release/src/lib/plugin-noop.js" | ||
} | ||
}, | ||
"jshintConfig": { | ||
@@ -33,12 +47,14 @@ "node": true | ||
"devDependencies": { | ||
"chai": "~1.9.1", | ||
"jenkins-mocha": "^2.6.0", | ||
"jshint": "^2.9.2", | ||
"sinon": "~1.10.3" | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.11", | ||
"jshint": "^2.11.0", | ||
"mocha": "^7.1.1", | ||
"nyc": "^15.0.0", | ||
"sinon": "^9.0.1" | ||
}, | ||
"dependencies": { | ||
"css-color-names": "~0.0.3", | ||
"dot": "~1.0.2", | ||
"svgo": "~0.4.5" | ||
"css-color-names": "~1.0.1", | ||
"dot": "^1.1.3", | ||
"svgo": "^1.3.2" | ||
} | ||
} |
@@ -5,2 +5,4 @@ # badge-up | ||
[![downloads](https://img.shields.io/npm/dt/badge-up.svg?maxAge=2592000)](https://www.npmjs.com/package/badge-up) | ||
[![build](https://cd.screwdriver.cd/pipelines/62/badge?maxAge=2592000)](https://cd.screwdriver.cd/pipelines/62) | ||
[![coverage](https://coveralls.io/repos/github/yahoo/badge-up/badge.svg)](https://coveralls.io/github/yahoo/badge-up) | ||
@@ -18,3 +20,3 @@ This is a simple library that generates SVG badges without Cairo. | ||
```js | ||
var badge = require('badge-up'); | ||
const badge = require('badge-up'); | ||
badge('batman', 'component', badge.colors.green, function (error, svg) { | ||
@@ -30,3 +32,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 | ||
@@ -53,9 +67,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) { | ||
@@ -68,2 +82,20 @@ // some callback | ||
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) { | ||
// | ||
} | ||
}()); | ||
``` |
24
v2.js
@@ -13,4 +13,10 @@ /* | ||
SVGO = require('svgo'), | ||
svgo = new SVGO(), | ||
svgo = new SVGO({ | ||
plugins: [{ | ||
sortDefsChildren: false | ||
}] | ||
}), | ||
TEMPLATE = dot.template(fs.readFileSync(path.join(__dirname, 'templates', 'v2.svg'), 'utf-8')), | ||
COLOR_REGEX = /^[0-9a-f]{6}$/i, | ||
STROKE_REGEX = /^s\{(.+?)\}$/i, | ||
DEFAULT_COLOR_FIRST = '#696969', // dimgrey | ||
@@ -30,3 +36,3 @@ DEFAULT_COLOR_REST = '#d3d3d3', // lightgrey | ||
function getColorCode(input) { | ||
if (input.match(/^[0-9a-f]{6}$/i)) { | ||
if (COLOR_REGEX.test(input)) { | ||
return '#' + input.toLowerCase(); | ||
@@ -64,9 +70,6 @@ } | ||
section.forEach(function(attribute) { | ||
// stroke attribute `s{color}` as CSS color or color code in hex | ||
var strokeAttribute = attribute.match(/^s\{(.*?)\}/i); | ||
if (strokeAttribute && strokeAttribute.length > 0) { | ||
if (getColorCode(strokeAttribute[1])) { | ||
sectionData.stroke = getColorCode(strokeAttribute[1]); | ||
} | ||
var strokeAttribute = STROKE_REGEX.exec(attribute); | ||
if (strokeAttribute) { | ||
sectionData.stroke = getColorCode(strokeAttribute[1]) || null; | ||
} | ||
@@ -106,4 +109,5 @@ | ||
var raw = TEMPLATE(sectionsToData(sections)); | ||
svgo.optimize(raw, function(optimized) { | ||
callback(undefined, optimized.data); | ||
return svgo.optimize(raw).then(function(optimized) { | ||
if (callback) callback(undefined, optimized.data); | ||
return optimized.data; | ||
}); | ||
@@ -110,0 +114,0 @@ }; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
212
97
16337
6
1
+ Added@types/q@1.5.8(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarray.prototype.reduce@1.0.7(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedboolbase@1.0.0(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcoa@2.0.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcss-color-names@1.0.1(transitive)
+ Addedcss-select@2.1.0(transitive)
+ Addedcss-select-base-adapter@0.1.1(transitive)
+ Addedcss-tree@1.0.0-alpha.371.1.3(transitive)
+ Addedcss-what@3.4.2(transitive)
+ Addedcsso@4.2.0(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddom-serializer@0.2.2(transitive)
+ Addeddomelementtype@1.3.12.3.0(transitive)
+ Addeddomutils@1.7.0(transitive)
+ Addeddot@1.1.3(transitive)
+ Addedentities@2.2.0(transitive)
+ Addedes-abstract@1.23.3(transitive)
+ Addedes-array-method-boxes-properly@1.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedmdn-data@2.0.142.0.4(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addednth-check@1.0.2(transitive)
+ Addedobject-inspect@1.13.2(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedobject.getownpropertydescriptors@2.1.8(transitive)
+ Addedobject.values@1.2.0(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedq@1.5.1(transitive)
+ Addedregexp.prototype.flags@1.5.2(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedsax@1.2.4(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstable@0.1.8(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedsvgo@1.3.2(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.2(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addedunquote@1.1.1(transitive)
+ Addedutil.promisify@1.0.1(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
- Removedargparse@0.1.16(transitive)
- Removedcoa@0.4.1(transitive)
- Removedcolors@0.6.2(transitive)
- Removedcss-color-names@0.0.4(transitive)
- Removeddot@1.0.3(transitive)
- Removedesprima@1.0.4(transitive)
- Removedjs-yaml@2.1.3(transitive)
- Removedq@0.9.7(transitive)
- Removedsax@0.6.1(transitive)
- Removedsvgo@0.4.5(transitive)
- Removedunderscore@1.7.0(transitive)
- Removedunderscore.string@2.4.0(transitive)
- Removedwhet.extend@0.9.9(transitive)
Updatedcss-color-names@~1.0.1
Updateddot@^1.1.3
Updatedsvgo@^1.3.2