@iconify/tools 1.3.17 → 2.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintignore +2 -0
  3. package/lib/colors/attribs.d.ts +16 -0
  4. package/lib/colors/attribs.js +26 -0
  5. package/lib/colors/attribs.mjs +28 -0
  6. package/lib/colors/parse.d.ts +37 -0
  7. package/lib/colors/parse.js +261 -0
  8. package/lib/colors/parse.mjs +212 -0
  9. package/lib/css/parse.d.ts +4 -0
  10. package/lib/css/parse.js +23 -0
  11. package/lib/css/parse.mjs +20 -0
  12. package/lib/css/parser/error.d.ts +11 -0
  13. package/lib/css/parser/error.js +27 -0
  14. package/lib/css/parser/error.mjs +23 -0
  15. package/lib/css/parser/export.d.ts +5 -0
  16. package/lib/css/parser/export.js +69 -0
  17. package/lib/css/parser/export.mjs +46 -0
  18. package/lib/css/parser/strings.d.ts +13 -0
  19. package/lib/css/parser/strings.js +93 -0
  20. package/lib/css/parser/strings.mjs +74 -0
  21. package/lib/css/parser/text.d.ts +17 -0
  22. package/lib/css/parser/text.js +174 -0
  23. package/lib/css/parser/text.mjs +133 -0
  24. package/lib/css/parser/tokens.d.ts +6 -0
  25. package/lib/css/parser/tokens.js +200 -0
  26. package/lib/css/parser/tokens.mjs +186 -0
  27. package/lib/css/parser/tree.d.ts +5 -0
  28. package/lib/css/parser/tree.js +44 -0
  29. package/lib/css/parser/tree.mjs +40 -0
  30. package/lib/css/parser/types.d.ts +51 -0
  31. package/lib/css/parser/types.js +2 -0
  32. package/lib/css/parser/types.mjs +0 -0
  33. package/lib/icon-set/index.d.ts +134 -0
  34. package/lib/icon-set/index.js +776 -0
  35. package/lib/icon-set/index.mjs +617 -0
  36. package/lib/icon-set/match.d.ts +6 -0
  37. package/lib/icon-set/match.js +66 -0
  38. package/lib/icon-set/match.mjs +55 -0
  39. package/lib/icon-set/merge.d.ts +5 -0
  40. package/lib/icon-set/merge.js +91 -0
  41. package/lib/icon-set/merge.mjs +75 -0
  42. package/lib/icon-set/props.d.ts +10 -0
  43. package/lib/icon-set/props.js +33 -0
  44. package/lib/icon-set/props.mjs +25 -0
  45. package/lib/icon-set/types.d.ts +68 -0
  46. package/lib/icon-set/types.js +2 -0
  47. package/lib/icon-set/types.mjs +0 -0
  48. package/lib/import/directory.d.ts +35 -0
  49. package/lib/import/directory.js +59 -0
  50. package/lib/import/directory.mjs +47 -0
  51. package/lib/misc/keyword.d.ts +4 -0
  52. package/lib/misc/keyword.js +31 -0
  53. package/lib/misc/keyword.mjs +17 -0
  54. package/lib/misc/scan.d.ts +24 -0
  55. package/lib/misc/scan.js +48 -0
  56. package/lib/misc/scan.mjs +43 -0
  57. package/lib/optimise/flags.d.ts +5 -0
  58. package/lib/optimise/flags.js +303 -0
  59. package/lib/optimise/flags.mjs +241 -0
  60. package/lib/optimise/scale.d.ts +5 -0
  61. package/lib/optimise/scale.js +42 -0
  62. package/lib/optimise/scale.mjs +22 -0
  63. package/lib/optimise/svgo.d.ts +27 -0
  64. package/lib/optimise/svgo.js +88 -0
  65. package/lib/optimise/svgo.mjs +75 -0
  66. package/lib/svg/cleanup/attribs.d.ts +5 -0
  67. package/lib/svg/cleanup/attribs.js +43 -0
  68. package/lib/svg/cleanup/attribs.mjs +36 -0
  69. package/lib/svg/cleanup/bad-tags.d.ts +5 -0
  70. package/lib/svg/cleanup/bad-tags.js +69 -0
  71. package/lib/svg/cleanup/bad-tags.mjs +68 -0
  72. package/lib/svg/cleanup/inline-style.d.ts +5 -0
  73. package/lib/svg/cleanup/inline-style.js +77 -0
  74. package/lib/svg/cleanup/inline-style.mjs +65 -0
  75. package/lib/svg/cleanup/root-svg.d.ts +5 -0
  76. package/lib/svg/cleanup/root-svg.js +106 -0
  77. package/lib/svg/cleanup/root-svg.mjs +88 -0
  78. package/lib/svg/cleanup/svgo-style.d.ts +5 -0
  79. package/lib/svg/cleanup/svgo-style.js +35 -0
  80. package/lib/svg/cleanup/svgo-style.mjs +29 -0
  81. package/lib/svg/cleanup.d.ts +5 -0
  82. package/lib/svg/cleanup.js +24 -0
  83. package/lib/svg/cleanup.mjs +16 -0
  84. package/lib/svg/data/attributes.d.ts +71 -0
  85. package/lib/svg/data/attributes.js +403 -0
  86. package/lib/svg/data/attributes.mjs +352 -0
  87. package/lib/svg/data/tags.d.ts +89 -0
  88. package/lib/svg/data/tags.js +185 -0
  89. package/lib/svg/data/tags.mjs +136 -0
  90. package/lib/svg/index.d.ts +33 -0
  91. package/lib/svg/index.js +122 -0
  92. package/lib/svg/index.mjs +85 -0
  93. package/lib/svg/parse-style.d.ts +40 -0
  94. package/lib/svg/parse-style.js +131 -0
  95. package/lib/svg/parse-style.mjs +109 -0
  96. package/lib/svg/parse.d.ts +30 -0
  97. package/lib/svg/parse.js +49 -0
  98. package/lib/svg/parse.mjs +40 -0
  99. package/package.json +167 -13
  100. package/README.md +0 -576
  101. package/license.txt +0 -21
  102. package/sample/parse.js +0 -74
  103. package/sample/source/icon-close.svg +0 -15
  104. package/sample/source/icon-confirm.svg +0 -14
  105. package/sample/source/icon-search.svg +0 -16
  106. package/src/collection.js +0 -641
  107. package/src/colors/change_palette.js +0 -227
  108. package/src/colors/get_palette.js +0 -143
  109. package/src/colors/opacify.js +0 -195
  110. package/src/export/component.js +0 -482
  111. package/src/export/dir.js +0 -109
  112. package/src/export/json.js +0 -329
  113. package/src/export/phantomjs.js +0 -76
  114. package/src/export/phantomjs_script.js +0 -125
  115. package/src/export/png.js +0 -193
  116. package/src/export/svg.js +0 -55
  117. package/src/export/templates/component.md +0 -79
  118. package/src/export/templates/info.md +0 -3
  119. package/src/export/templates/sample-react-1.md +0 -21
  120. package/src/export/templates/sample-react-2.md +0 -15
  121. package/src/export/templates/sample-react.md +0 -11
  122. package/src/export/templates/sample-svelte.md +0 -11
  123. package/src/export/templates/sample-svelte1.md +0 -22
  124. package/src/export/templates/sample-svelte2.md +0 -13
  125. package/src/export/templates/sample-vue-0.md +0 -30
  126. package/src/export/templates/sample-vue-1.md +0 -25
  127. package/src/export/templates/sample-vue-2.md +0 -27
  128. package/src/export/templates/sample-vue.md +0 -28
  129. package/src/helpers.js +0 -43
  130. package/src/import/dir.js +0 -234
  131. package/src/import/font.js +0 -402
  132. package/src/import/json.js +0 -200
  133. package/src/import/svg.js +0 -60
  134. package/src/import/web_icons.js +0 -248
  135. package/src/modules.js +0 -50
  136. package/src/optimize/crop.js +0 -554
  137. package/src/optimize/crop_script.js +0 -525
  138. package/src/optimize/flags.js +0 -430
  139. package/src/optimize/scale.js +0 -72
  140. package/src/optimize/svgo.js +0 -161
  141. package/src/optimize/tags.js +0 -522
  142. package/src/shapes/convert.js +0 -264
  143. package/src/shapes/index.js +0 -135
  144. package/src/shapes/length.js +0 -707
  145. package/src/shapes/length_script.js +0 -105
  146. package/src/shapes/options.js +0 -60
  147. package/src/svg.js +0 -162
@@ -1,402 +0,0 @@
1
- /**
2
- * This file is part of the @iconify/tools package.
3
- *
4
- * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- 'use strict';
11
-
12
- const fs = require('fs');
13
- const cheerio = require('cheerio');
14
- const SVG = require('../svg');
15
- const Collection = require('../collection');
16
- const crop = require('../optimize/crop');
17
-
18
- /**
19
- * Default options
20
- *
21
- * @type {object}
22
- */
23
- const defaults = {
24
- // Collection prefix
25
- prefix: '',
26
-
27
- // Array of characters to ignore, false if none
28
- ignoreCharacters: false,
29
-
30
- // List of changes for font: {height: 1000}, false if no changes
31
- fontChanges: false,
32
-
33
- // List of changes for each character: [hex] = {height: 1000}
34
- characterChanges: Object.create(null),
35
-
36
- // Crop glyphs
37
- crop: false,
38
- };
39
-
40
- /**
41
- * Generate SVG code
42
- *
43
- * @param {object} character
44
- * @param {string} path
45
- * @returns {string}
46
- */
47
- function generateSVG(character, path) {
48
- return (
49
- '<svg ' +
50
- 'width="' +
51
- character.width +
52
- '" ' +
53
- 'height="' +
54
- character.height +
55
- '" ' +
56
- 'viewBox="0 0 ' +
57
- character.width +
58
- ' ' +
59
- character.height +
60
- '" ' +
61
- 'xmlns="http://www.w3.org/2000/svg" ' +
62
- 'xmlns:xlink="http://www.w3.org/1999/xlink"' +
63
- '>\n' +
64
- getSVGBody(character, path) +
65
- '</svg>'
66
- );
67
- }
68
-
69
- /**
70
- * Get SVG body
71
- *
72
- * @param character
73
- * @param path
74
- * @return {string}
75
- */
76
- function getSVGBody(character, path) {
77
- let svg = '';
78
-
79
- svg +=
80
- '\t<g transform="translate(' +
81
- (0 - character.left) +
82
- ' ' +
83
- (character.height + character.bottom) +
84
- ')">\n';
85
- svg += '\t\t<g transform="scale(1 -1)">\n';
86
- svg += '\t\t\t<path d="' + path + '" />\n';
87
- svg += '\t\t</g>\n';
88
- svg += '\t</g>\n';
89
-
90
- return svg;
91
- }
92
-
93
- /**
94
- * Apply option changes to object
95
- *
96
- * @param data
97
- * @param options
98
- */
99
- function applyOptions(data, options) {
100
- Object.keys(data).forEach(key => {
101
- if (options[key] !== void 0) {
102
- switch (typeof options[key]) {
103
- case 'function':
104
- data[key] = options[key](data[key], data);
105
- break;
106
-
107
- default:
108
- data[key] = options[key];
109
- }
110
- }
111
- });
112
- }
113
-
114
- /**
115
- * Load SVG font
116
- *
117
- * @param {string} source
118
- * @param {object} [options]
119
- * @return {Promise}
120
- */
121
- module.exports = (source, options) => {
122
- options = options === void 0 ? Object.create(null) : options;
123
- Object.keys(defaults).forEach(key => {
124
- if (options[key] === void 0) {
125
- options[key] = defaults[key];
126
- }
127
- });
128
-
129
- return new Promise((fulfill, reject) => {
130
- fs.readFile(source, 'utf8', (err, data) => {
131
- if (err) {
132
- // is source svg font?
133
- if (source.slice(0, 1) === '<') {
134
- data = source;
135
- } else {
136
- return reject(err);
137
- }
138
- }
139
-
140
- let svg = cheerio.load(data, {
141
- lowerCaseAttributeNames: false,
142
- xmlMode: true,
143
- });
144
-
145
- // Check root
146
- let $root = svg(':root');
147
- if (
148
- $root.length > 1 ||
149
- $root.get(0).tagName !== 'svg' ||
150
- !$root.children('defs').length
151
- ) {
152
- reject('Invalid SVG font');
153
- return;
154
- }
155
-
156
- // Crop queue
157
- let cropQueue = Object.create(null);
158
-
159
- // Find fonts
160
- let glyphs = new Collection(options.prefix);
161
-
162
- try {
163
- $root.children('defs').each((index, def) => {
164
- let $def = cheerio(def);
165
-
166
- $def.children('font').each((index, row) => {
167
- let $font = cheerio(row);
168
-
169
- let $ff = $font.children('font-face');
170
- if ($ff.length !== 1) {
171
- console.log('Font is missing font-face');
172
- return;
173
- }
174
-
175
- let font = {
176
- width: 0,
177
- height: 0,
178
- ascent: 0,
179
- descent: 0,
180
- box: false,
181
- };
182
-
183
- let fontAttributes = row.attribs,
184
- ffAttributes = $ff.get(0).attribs;
185
-
186
- // Get width
187
- if (
188
- ffAttributes['units-per-em'] &&
189
- parseInt(ffAttributes['units-per-em'])
190
- ) {
191
- font.width = parseInt(ffAttributes['units-per-em']);
192
- }
193
- if (
194
- ffAttributes['horiz-adv-x'] &&
195
- parseInt(ffAttributes['horiz-adv-x'])
196
- ) {
197
- font.width = Math.abs(parseInt(ffAttributes['horiz-adv-x']));
198
- } else if (
199
- fontAttributes['horiz-adv-x'] &&
200
- parseInt(fontAttributes['horiz-adv-x'])
201
- ) {
202
- font.width = Math.abs(parseInt(fontAttributes['horiz-adv-x']));
203
- }
204
-
205
- // Get height
206
- ['ascent', 'descent'].forEach(key => {
207
- if (ffAttributes[key] !== void 0) {
208
- font[key] = parseFloat(ffAttributes[key]);
209
- if (isNaN(font[key])) {
210
- throw new Error(
211
- 'Invalid number for ' + key + ': ' + ffAttributes[key]
212
- );
213
- }
214
- }
215
- });
216
-
217
- font.height =
218
- font.ascent === font.descent
219
- ? font.width
220
- : font.ascent - font.descent;
221
-
222
- // // Get bounding box
223
- // if (ffAttributes.bbox) {
224
- // font.box = ffAttributes.bbox.split(' ').map(item => {
225
- // let result = parseFloat(item);
226
- // if (isNaN(result)) {
227
- // throw new Error('Invalid bounding box value: ' + ff.bbox);
228
- // }
229
- // return result;
230
- // });
231
- // }
232
-
233
- if (!font.width || !font.height) {
234
- throw new Error('SVG is missing required attributed');
235
- }
236
-
237
- // Get all glyphs
238
- $font.children('glyph').each((index, row) => {
239
- let $glyph = cheerio(row),
240
- glyphAttributes = row.attribs;
241
-
242
- if (
243
- glyphAttributes.d === void 0 ||
244
- glyphAttributes.d.length < 6 ||
245
- glyphAttributes.unicode === void 0
246
- ) {
247
- return;
248
- }
249
-
250
- // Get character hexadecimal value
251
- let key = glyphAttributes.unicode.codePointAt(0);
252
- if (isNaN(key)) {
253
- return;
254
- }
255
- let hex = key.toString(16);
256
-
257
- // Check if character is ignored
258
- if (
259
- options.ignoreCharacters &&
260
- options.ignoreCharacters.indexOf(hex) !== -1
261
- ) {
262
- return;
263
- }
264
-
265
- let character = Object.assign(
266
- {
267
- key: hex,
268
- left: 0,
269
- bottom: 0,
270
- },
271
- font
272
- );
273
-
274
- // Set custom width from horiz-adv-x attribute
275
- if (
276
- glyphAttributes['horiz-adv-x'] &&
277
- parseInt(glyphAttributes['horiz-adv-x'])
278
- ) {
279
- character.width = Math.abs(
280
- parseInt(glyphAttributes['horiz-adv-x'])
281
- );
282
- }
283
-
284
- // Overwrite ascent/descent
285
- ['ascent', 'descent'].forEach(key => {
286
- if (glyphAttributes[key] !== void 0) {
287
- character[key] = parseInt(glyphAttributes[key]);
288
- }
289
- });
290
-
291
- character.bottom = character.descent;
292
- character.height =
293
- character.ascent === character.descent
294
- ? character.width
295
- : character.ascent - character.descent;
296
-
297
- // // Change coordinates to bounding box
298
- // if (character.box !== false) {
299
- // character.bottom = character.box[1];
300
- // if (character.box[3] - character.box[1] > character.height) {
301
- // character.height = character.box[3] - character.box[1];
302
- // }
303
- // }
304
-
305
- // Check options
306
- let oldHeight = character.height;
307
-
308
- // Custom font changes
309
- if (options.fontChanges) {
310
- applyOptions(character, options.fontChanges);
311
- }
312
- if (options.characterChanges && options.characterChanges[hex]) {
313
- applyOptions(character, options.characterChanges[hex]);
314
- }
315
-
316
- // Adjust bottom position for custom height
317
- if (character.height !== oldHeight) {
318
- character.bottom += (oldHeight - character.height) / 2;
319
- if (
320
- options.fontChanges &&
321
- options.fontChanges.bottom !== void 0
322
- ) {
323
- applyOptions(character, options.fontChanges);
324
- }
325
- if (
326
- options.characterChanges &&
327
- options.characterChanges[hex] &&
328
- options.characterChanges[hex].bottom !== void 0
329
- ) {
330
- applyOptions(character, options.characterChanges[hex]);
331
- }
332
- }
333
-
334
- // Save item
335
- let verticalAlign =
336
- Math.round(
337
- (font.descent / (font.ascent - font.descent)) * 1000
338
- ) / 1000;
339
- if (options.crop !== false) {
340
- cropQueue[hex] = {
341
- body: getSVGBody(character, glyphAttributes['d']),
342
- ascent: font.ascent,
343
- descent: font.descent,
344
- width: character.width,
345
- originalHeight: character.height,
346
- verticalAlign: verticalAlign,
347
- };
348
- }
349
- try {
350
- let svg = new SVG(generateSVG(character, glyphAttributes['d']));
351
- svg.inlineTop = 0;
352
- svg.inlineHeight = character.height;
353
- svg.verticalAlign = verticalAlign;
354
- glyphs.add(hex, svg);
355
- } catch (err) {}
356
- });
357
- });
358
- });
359
- } catch (err) {
360
- reject(err);
361
- }
362
-
363
- // Crop images
364
- if (Object.keys(cropQueue).length) {
365
- let cropOptions = Object.assign(
366
- {
367
- defaultRightLimit: false,
368
- defaultLeftLimit: false,
369
- },
370
- typeof options.crop === 'object' ? options.crop : Object.create(null)
371
- );
372
-
373
- cropOptions.multiple = true;
374
- cropOptions.format = 'svg';
375
-
376
- // Need to run SVGO before cropping to remove transformations because PhantomJS has bugs with transformations
377
- cropOptions.optimize = true;
378
-
379
- crop(cropQueue, cropOptions)
380
- .then(results => {
381
- Object.keys(results).forEach(hex => {
382
- let svg = results[hex];
383
-
384
- // top > 0 - something was cropped above icon
385
- svg.inlineTop =
386
- svg._cropData.top <= 0 ? 0 : 0 - svg._cropData.top;
387
- svg.inlineHeight = cropQueue[hex].originalHeight;
388
- svg.verticalAlign = cropQueue[hex].verticalAlign;
389
-
390
- glyphs.add(hex, svg);
391
- });
392
- fulfill(glyphs);
393
- })
394
- .catch(err => {
395
- reject(err);
396
- });
397
- } else {
398
- fulfill(glyphs);
399
- }
400
- });
401
- });
402
- };
@@ -1,200 +0,0 @@
1
- /**
2
- * This file is part of the @iconify/tools package.
3
- *
4
- * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- 'use strict';
11
-
12
- const fs = require('fs');
13
- const SVG = require('../svg');
14
- const Collection = require('../collection');
15
- const deOptimize = require('@iconify/json-tools').Collection.deOptimize;
16
-
17
- const defaults = {
18
- reject: true,
19
- detectPrefix: false,
20
- };
21
-
22
- const extraAttributes = [
23
- 'inlineHeight',
24
- 'inlineTop',
25
- 'verticalAlign',
26
- 'rotate',
27
- 'vFlip',
28
- 'hFlip',
29
- 'deprecated',
30
- 'hidden',
31
- 'renamed',
32
- ];
33
-
34
- const extraObjects = ['themes', 'info', 'prefixes', 'suffixes'];
35
-
36
- /**
37
- * Import icons from json file or string
38
- */
39
- module.exports = (source, options) => {
40
- options = options === void 0 ? Object.create(null) : options;
41
- Object.keys(defaults).forEach((key) => {
42
- if (options[key] === void 0) {
43
- options[key] = defaults[key];
44
- }
45
- });
46
-
47
- return new Promise((fulfill, reject) => {
48
- // Loaded file
49
- function loaded(json) {
50
- if (typeof json !== 'object' || json.icons === void 0) {
51
- if (options.reject) {
52
- reject('Invalid JSON file');
53
- } else {
54
- fulfill(null);
55
- }
56
- return;
57
- }
58
-
59
- let collection = new Collection(
60
- json.prefix === void 0 ? '' : json.prefix
61
- );
62
-
63
- try {
64
- // Expand all keys
65
- deOptimize(json);
66
-
67
- // Add items
68
- Object.keys(json.icons).forEach((key) => {
69
- let data = json.icons[key];
70
- if (!data.width || !data.height || !data.body) {
71
- return;
72
- }
73
-
74
- let viewbox =
75
- (data.left === void 0 ? 0 : data.left) +
76
- ' ' +
77
- (data.top === void 0 ? 0 : data.top) +
78
- ' ' +
79
- data.width +
80
- ' ' +
81
- data.height;
82
- let svg = new SVG(
83
- '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="' +
84
- viewbox +
85
- '">' +
86
- data.body +
87
- '</svg>'
88
- );
89
-
90
- // Copy additional attributes
91
- extraAttributes.forEach((attr) => {
92
- if (data[attr] !== void 0) {
93
- svg[attr] = data[attr];
94
- }
95
- });
96
-
97
- // Check for aliases
98
- if (json.aliases !== void 0) {
99
- Object.keys(json.aliases).forEach((aliasKey) => {
100
- if (json.aliases[aliasKey].parent === key) {
101
- // Found alias
102
- if (svg.aliases === void 0) {
103
- svg.aliases = [];
104
- }
105
- let alias = Object.assign(
106
- Object.create(null),
107
- json.aliases[aliasKey]
108
- );
109
- delete alias.parent;
110
- alias.name = aliasKey;
111
- svg.aliases.push(alias);
112
- }
113
- });
114
- }
115
-
116
- // Add to collection
117
- collection.add(key, svg);
118
- });
119
-
120
- // Add characters
121
- if (json.chars !== void 0) {
122
- Object.keys(json.chars).forEach((char) => {
123
- let icon = json.chars[char];
124
- if (collection.items[icon] !== void 0) {
125
- collection.items[icon].char = char;
126
- }
127
- });
128
- }
129
-
130
- // Add categories
131
- if (json.categories) {
132
- Object.keys(json.categories).forEach((cat) => {
133
- json.categories[cat].forEach((icon) => {
134
- if (collection.items[icon] !== void 0) {
135
- if (collection.items[icon].category === void 0) {
136
- collection.items[icon].category = [cat];
137
- } else {
138
- collection.items[icon].category.push(cat);
139
- }
140
- }
141
- });
142
- });
143
- }
144
-
145
- // Add themes and info
146
- extraObjects.forEach((key) => {
147
- if (typeof json[key] === 'object') {
148
- collection[key] = json[key];
149
- }
150
- });
151
- } catch (err) {
152
- collection = null;
153
- }
154
-
155
- if (collection === null || !collection.length()) {
156
- if (options.reject) {
157
- reject('Invalid JSON file');
158
- } else {
159
- fulfill(null);
160
- }
161
- return;
162
- }
163
-
164
- if (options.detectPrefix) {
165
- collection.findCommonPrefix(true);
166
- }
167
-
168
- fulfill(collection);
169
- }
170
-
171
- // Check if source is JSON string
172
- if (source.slice(0, 1) === '{') {
173
- try {
174
- let data = JSON.parse(source);
175
- process.nextTick(function () {
176
- loaded(data);
177
- });
178
- return;
179
- } catch (err) {}
180
- }
181
-
182
- // Load from file
183
- fs.readFile(source, 'utf8', (err, data) => {
184
- if (err) {
185
- if (options.reject) {
186
- reject(err);
187
- } else {
188
- fulfill(null);
189
- }
190
- return;
191
- }
192
-
193
- let json = null;
194
- try {
195
- json = JSON.parse(data);
196
- } catch (err) {}
197
- loaded(json);
198
- });
199
- });
200
- };
package/src/import/svg.js DELETED
@@ -1,60 +0,0 @@
1
- /**
2
- * This file is part of the @iconify/tools package.
3
- *
4
- * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- 'use strict';
11
-
12
- const fs = require('fs');
13
- const SVG = require('../svg');
14
-
15
- const defaults = {
16
- reject: true,
17
- contentCallback: null,
18
- headless: true,
19
- minify: true,
20
- };
21
-
22
- /**
23
- * Import from .svg file
24
- */
25
- module.exports = (source, options) => {
26
- options = options === void 0 ? Object.create(null) : options;
27
- Object.keys(defaults).forEach(key => {
28
- if (options[key] === void 0) {
29
- options[key] = defaults[key];
30
- }
31
- });
32
-
33
- return new Promise((fulfill, reject) => {
34
- fs.readFile(source, 'utf8', (err, data) => {
35
- let svg;
36
-
37
- if (err) {
38
- if (options.reject) {
39
- reject(err);
40
- } else {
41
- fulfill(null);
42
- }
43
- } else {
44
- if (options.contentCallback) {
45
- data = options.contentCallback(data);
46
- }
47
- try {
48
- svg = new SVG(data);
49
- } catch (err) {
50
- if (options.reject) {
51
- reject('Invalid SVG file');
52
- } else {
53
- fulfill(null);
54
- }
55
- }
56
- fulfill(svg);
57
- }
58
- });
59
- });
60
- };