mirror of https://github.com/iconify/api.git
Fix error preventing 'constructor' from being valid icon name
This commit is contained in:
parent
a34b843be8
commit
0f11b4a903
2
app.js
2
app.js
|
|
@ -108,7 +108,7 @@ if (!app.dirs.getRepos().length) {
|
|||
}
|
||||
|
||||
// Collections
|
||||
app.collections = {};
|
||||
app.collections = Object.create(null);
|
||||
app.reload = require('./src/reload').bind(this, app);
|
||||
|
||||
// Sync module
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
"optional": true
|
||||
},
|
||||
"@iconify/json-tools": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@iconify/json-tools/-/json-tools-1.0.1.tgz",
|
||||
"integrity": "sha512-A15I5GRny9gDZIfgu4nutUzdMsG0Bd2Ju6GbochRLu/ZSoMSH22L8mQrQdvdj0U/ydzR68mktUXrPUyG786Zlw=="
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@iconify/json-tools/-/json-tools-1.0.5.tgz",
|
||||
"integrity": "sha512-CfgaLFnd+fuXg2zcxI2/LZpFZHcPUl8BmNNzeP2usLw+Z+JPDwibt8H41pJ86dy8ADMONsTBeTpkFXLh+n9Gsw=="
|
||||
},
|
||||
"accepts": {
|
||||
"version": "1.3.5",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "2.0.0-beta1",
|
||||
"version": "2.0.0-beta2",
|
||||
"description": "Node.js version of api.iconify.design",
|
||||
"private": true,
|
||||
"main": "app.js",
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
"url": "git+ssh://git@github.com/iconify-design/api.js.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@iconify/json-tools": "^1.0.0-beta2",
|
||||
"@iconify/json-tools": "^1.0.5",
|
||||
"express": "^4.16.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
10
src/dirs.js
10
src/dirs.js
|
|
@ -19,9 +19,9 @@ const fs = require('fs');
|
|||
* @returns {object}
|
||||
*/
|
||||
module.exports = app => {
|
||||
let functions = {},
|
||||
dirs = {},
|
||||
custom = {},
|
||||
let functions = Object.create(null),
|
||||
dirs = Object.create(null),
|
||||
custom = Object.create(null),
|
||||
repos = [],
|
||||
storageDir = null,
|
||||
versionsFile = null;
|
||||
|
|
@ -132,7 +132,7 @@ module.exports = app => {
|
|||
*/
|
||||
|
||||
// Get synchronized repositories
|
||||
let cached = {};
|
||||
let cached = Object.create(null);
|
||||
app.config.canSync = false;
|
||||
try {
|
||||
if (app.config.sync.versions && app.config.sync.storage) {
|
||||
|
|
@ -147,7 +147,7 @@ module.exports = app => {
|
|||
}
|
||||
} catch (err) {
|
||||
if (typeof cached !== 'object') {
|
||||
cached = {};
|
||||
cached = Object.create(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ let functions = {
|
|||
if (err) {
|
||||
_app.error('Error deleting file ' + file, Object.assign({
|
||||
key: 'unlink-' + file
|
||||
}, typeof options === 'object' ? options : {}));
|
||||
}, typeof options === 'object' ? options : Object.create(null)));
|
||||
}
|
||||
fulfill();
|
||||
})
|
||||
|
|
@ -42,7 +42,7 @@ let functions = {
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
rmdir: (dir, options) => new Promise((fulfill, reject) => {
|
||||
options = typeof options === 'object' ? options : {};
|
||||
options = typeof options === 'object' ? options : Object.create(null);
|
||||
|
||||
function done() {
|
||||
fs.rmdir(dir, err => {
|
||||
|
|
@ -62,7 +62,7 @@ let functions = {
|
|||
return;
|
||||
}
|
||||
|
||||
let children = {};
|
||||
let children = Object.create(null);
|
||||
|
||||
files.forEach(file => {
|
||||
let filename = dir + '/' + file,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const fs = require('fs');
|
|||
const util = require('util');
|
||||
|
||||
// List of imported modules
|
||||
let imported = {};
|
||||
let imported = Object.create(null);
|
||||
|
||||
/**
|
||||
* Import json file
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ const defaultOptions = {
|
|||
};
|
||||
|
||||
// List of notices that are sent only once per session
|
||||
let logged = {};
|
||||
let logged = Object.create(null);
|
||||
|
||||
// List of throttled messages
|
||||
let throttled = null;
|
||||
|
|
@ -54,7 +54,7 @@ const sendQueue = app => {
|
|||
* @param {object|boolean} [options]
|
||||
*/
|
||||
module.exports = (app, error, message, options) => {
|
||||
options = Object.assign({}, defaultOptions, options === void 0 ? {} : (typeof options === 'boolean' ? {
|
||||
options = Object.assign(Object.create(null), defaultOptions, options === void 0 ? Object.create(null) : (typeof options === 'boolean' ? {
|
||||
log: options
|
||||
}: options));
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ const defaultOptions = {
|
|||
logger: null
|
||||
};
|
||||
|
||||
let repoItems = {},
|
||||
collectionRepos = {},
|
||||
hashes = {},
|
||||
let repoItems = Object.create(null),
|
||||
collectionRepos = Object.create(null),
|
||||
hashes = Object.create(null),
|
||||
nextReload = 0;
|
||||
|
||||
class Loader {
|
||||
|
|
@ -257,7 +257,7 @@ class Loader {
|
|||
*/
|
||||
module.exports = (app, repos, options) => new Promise((fulfill, reject) => {
|
||||
// Options
|
||||
options = Object.assign({}, defaultOptions, typeof options === 'object' ? options : {});
|
||||
options = Object.assign(Object.create(null), defaultOptions, typeof options === 'object' ? options : Object.create(null));
|
||||
|
||||
// Get list of repositories to reload
|
||||
let availableRepos = app.dirs.getRepos();
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ const defaultOptions = {
|
|||
reload: true
|
||||
};
|
||||
|
||||
let active = {},
|
||||
queued = {};
|
||||
let active = Object.create(null),
|
||||
queued = Object.create(null);
|
||||
|
||||
class Sync {
|
||||
constructor(app, repo, options) {
|
||||
|
|
@ -108,7 +108,7 @@ class Sync {
|
|||
|
||||
module.exports = (app, repo, options) => new Promise((fulfill, reject) => {
|
||||
// Options
|
||||
options = Object.assign({}, defaultOptions, typeof options !== 'object' ? options : {});
|
||||
options = Object.assign(Object.create(null), defaultOptions, typeof options !== 'object' ? options : Object.create(null));
|
||||
|
||||
// Check if synchronization is disabled
|
||||
if (!app.config.canSync || !app.config.sync[repo] || !app.config.sync.git) {
|
||||
|
|
|
|||
|
|
@ -84,16 +84,38 @@
|
|||
expect(parseQuery('test1', 'icons', 'js', {
|
||||
icons: 'alias1'
|
||||
})).to.be.eql({
|
||||
type: 'application/javascript; charset=utf-8',
|
||||
body: 'SimpleSVG._loaderCallback({"prefix":"test","icons":{"icon2":{"body":"<icon2 />"}},"aliases":{"alias1":{"parent":"icon2","hFlip":true}},"width":24,"height":24})'
|
||||
js: true,
|
||||
defaultCallback: 'SimpleSVG._loaderCallback',
|
||||
data: {
|
||||
prefix: 'test',
|
||||
icons: {
|
||||
icon2: { body: '<icon2 />' }
|
||||
},
|
||||
aliases: {
|
||||
alias1: { parent: 'icon2', hFlip: true }
|
||||
},
|
||||
width: 24,
|
||||
height: 24
|
||||
}
|
||||
});
|
||||
|
||||
// Query collection without prefix, json
|
||||
expect(parseQuery('test2', 'icons', 'json', {
|
||||
icons: 'alias1'
|
||||
})).to.be.eql({
|
||||
type: 'application/json; charset=utf-8',
|
||||
body: '{"prefix":"test2","icons":{"icon2":{"body":"<icon2 />"}},"aliases":{"alias1":{"parent":"icon2","hFlip":true}},"width":24,"height":24}'
|
||||
js: false,
|
||||
defaultCallback: 'SimpleSVG._loaderCallback',
|
||||
data: {
|
||||
prefix: 'test2',
|
||||
icons: {
|
||||
icon2: { body: '<icon2 />' }
|
||||
},
|
||||
aliases: {
|
||||
alias1: { parent: 'icon2', hFlip: true }
|
||||
},
|
||||
width: 24,
|
||||
height: 24
|
||||
}
|
||||
});
|
||||
|
||||
// Custom callback
|
||||
|
|
@ -101,8 +123,17 @@
|
|||
icons: 'icon1,icon2',
|
||||
callback: 'console.log'
|
||||
})).to.be.eql({
|
||||
type: 'application/javascript; charset=utf-8',
|
||||
body: 'console.log({"prefix":"test","icons":{"icon1":{"body":"<icon1 fill=\\"currentColor\\" />","width":30},"icon2":{"body":"<icon2 />"}},"width":24,"height":24})'
|
||||
js: true,
|
||||
defaultCallback: 'SimpleSVG._loaderCallback',
|
||||
data: {
|
||||
prefix: 'test',
|
||||
icons: {
|
||||
icon1: { body: '<icon1 fill="currentColor" />', width: 30 },
|
||||
icon2: { body: '<icon2 />' }
|
||||
},
|
||||
width: 24,
|
||||
height: 24
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -112,7 +143,7 @@
|
|||
})).to.be.eql({
|
||||
filename: 'icon1.svg',
|
||||
type: 'image/svg+xml; charset=utf-8',
|
||||
body: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1.25em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 30 24"><icon1 fill="currentColor" /></svg>'
|
||||
body: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1.25em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 30 24" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);"><icon1 fill="currentColor" /></svg>'
|
||||
});
|
||||
|
||||
// Icon with custom attributes
|
||||
|
|
@ -121,7 +152,7 @@
|
|||
})).to.be.eql({
|
||||
filename: 'alias1.svg',
|
||||
type: 'image/svg+xml; charset=utf-8',
|
||||
body: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g transform="translate(24 0) scale(-1 1)"><icon2 /></g></svg>'
|
||||
body: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);"><g transform="translate(24 0) scale(-1 1)"><icon2 /></g></svg>'
|
||||
});
|
||||
|
||||
// Icon with id replacement
|
||||
|
|
@ -130,7 +161,7 @@
|
|||
rotate: '90deg'
|
||||
}).body.replace(/IconifyId-[0-9a-f]+-[0-9a-f]+-[0-9]+/g, 'some-id');
|
||||
|
||||
expect(result).to.be.equal('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g transform="rotate(90 12 12)"><defs><foo id="some-id" /></defs><bar use="url(#some-id)" fill="red" stroke="red" /></g></svg>');
|
||||
expect(result).to.be.equal('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);"><g transform="rotate(90 12 12)"><defs><foo id="some-id" /></defs><bar use="url(#some-id)" fill="red" stroke="red" /></g></svg>');
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in New Issue