@primer/octicons
Advanced tools
Comparing version 0.0.0-0e0f672 to 0.0.0-0e54ab1
42
index.js
const data = require('./build/data.json') | ||
const objectAssign = require('object-assign') | ||
const DEFAULT_HEIGHT = 16 | ||
for (const key of Object.keys(data)) { | ||
// Returns a string representation of html attributes | ||
const htmlAttributes = (icon, options) => { | ||
const htmlAttributes = (icon, defaultOptions, options) => { | ||
const attributes = [] | ||
const attrObj = objectAssign({}, data[key].options, options) | ||
const attrObj = objectAssign({}, defaultOptions, options) | ||
@@ -16,6 +18,6 @@ // If the user passed in options | ||
? options['width'] | ||
: (parseInt(options['height']) * data[key].options['width']) / data[key].options['height'] | ||
: (parseInt(options['height']) * defaultOptions['width']) / defaultOptions['height'] | ||
attrObj['height'] = options['height'] | ||
? options['height'] | ||
: (parseInt(options['width']) * data[key].options['height']) / data[key].options['width'] | ||
: (parseInt(options['width']) * defaultOptions['height']) / defaultOptions['width'] | ||
} | ||
@@ -49,15 +51,21 @@ | ||
// Set all the default options | ||
data[key].options = { | ||
version: '1.1', | ||
width: data[key].width, | ||
height: data[key].height, | ||
viewBox: `0 0 ${data[key].width} ${data[key].height}`, | ||
class: `octicon octicon-${key}`, | ||
'aria-hidden': 'true' | ||
// Set options for each icon height | ||
for (const height of Object.keys(data[key].heights)) { | ||
data[key].heights[height].options = { | ||
version: '1.1', | ||
width: data[key].heights[height].width, | ||
height: parseInt(height), | ||
viewBox: `0 0 ${data[key].heights[height].width} ${height}`, | ||
class: `octicon octicon-${key}`, | ||
'aria-hidden': 'true' | ||
} | ||
} | ||
// Function to return an SVG object | ||
data[key].toSVG = function(options) { | ||
return `<svg ${htmlAttributes(data[key], options)}>${data[key].path}</svg>` | ||
data[key].toSVG = function (options = {}) { | ||
const {height, width} = options | ||
const naturalHeight = closestNaturalHeight(Object.keys(data[key].heights), height || width || DEFAULT_HEIGHT) | ||
return `<svg ${htmlAttributes(data[key], data[key].heights[naturalHeight].options, options)}>${ | ||
data[key].heights[naturalHeight].path | ||
}</svg>` | ||
} | ||
@@ -68,1 +76,7 @@ } | ||
module.exports = data | ||
function closestNaturalHeight(naturalHeights, height) { | ||
return naturalHeights | ||
.map(naturalHeight => parseInt(naturalHeight, 10)) | ||
.reduce((acc, naturalHeight) => (naturalHeight <= height ? naturalHeight : acc), naturalHeights[0]) | ||
} |
{ | ||
"name": "@primer/octicons", | ||
"version": "0.0.0-0e0f672", | ||
"version": "0.0.0-0e54ab1", | ||
"description": "A scalable set of icons handcrafted with <3 by GitHub.", | ||
"homepage": "https://octicons.github.com", | ||
"homepage": "https://primer.style/octicons", | ||
"author": "GitHub Inc.", | ||
@@ -20,3 +20,3 @@ "license": "MIT", | ||
"scripts": { | ||
"build": "script/build.js", | ||
"build": "\\cp -r ../build/ ./build && \\cp index.scss ./build/build.css", | ||
"lint": "eslint index.js tests/*.js", | ||
@@ -35,6 +35,24 @@ "test": "ava --verbose 'tests/*.js'" | ||
"devDependencies": { | ||
"@github/prettier-config": "0.0.4", | ||
"ava": "^0.22.0", | ||
"eslint": "^6.5.1", | ||
"eslint-plugin-github": "^3.1.3" | ||
"eslint-plugin-github": "4.1.3" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"plugin:github/internal", | ||
"plugin:github/recommended" | ||
], | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
"requireConfigFile": false | ||
}, | ||
"rules": { | ||
"github/no-then": 0 | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
1021695
934
1870
4
1