@iconify/tools 2.1.0 → 2.1.1

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 (114) hide show
  1. package/lib/colors/detect.cjs +68 -0
  2. package/lib/colors/detect.d.ts +15 -0
  3. package/lib/colors/detect.mjs +64 -0
  4. package/lib/colors/parse.cjs +31 -7
  5. package/lib/colors/parse.d.ts +1 -1
  6. package/lib/colors/parse.mjs +31 -7
  7. package/lib/colors/validate.cjs +9 -3
  8. package/lib/colors/validate.d.ts +1 -1
  9. package/lib/colors/validate.mjs +9 -3
  10. package/lib/css/parser/error.cjs +1 -1
  11. package/lib/css/parser/error.mjs +1 -1
  12. package/lib/css/parser/strings.cjs +10 -2
  13. package/lib/css/parser/strings.mjs +10 -2
  14. package/lib/css/parser/tokens.cjs +133 -109
  15. package/lib/css/parser/tokens.mjs +133 -109
  16. package/lib/download/api/cache.cjs +28 -21
  17. package/lib/download/api/cache.mjs +28 -21
  18. package/lib/download/git/branch.cjs +1 -1
  19. package/lib/download/git/branch.mjs +1 -1
  20. package/lib/download/git/hash.cjs +1 -1
  21. package/lib/download/git/hash.mjs +1 -1
  22. package/lib/download/git/index.cjs +7 -4
  23. package/lib/download/git/index.mjs +7 -4
  24. package/lib/download/git/reset.cjs +1 -2
  25. package/lib/download/git/reset.mjs +1 -2
  26. package/lib/download/github/index.cjs +10 -7
  27. package/lib/download/github/index.mjs +10 -7
  28. package/lib/download/gitlab/hash.cjs +3 -1
  29. package/lib/download/gitlab/hash.mjs +3 -1
  30. package/lib/download/gitlab/index.cjs +9 -6
  31. package/lib/download/gitlab/index.mjs +9 -6
  32. package/lib/download/index.cjs +4 -3
  33. package/lib/download/index.mjs +4 -3
  34. package/lib/download/npm/index.cjs +12 -8
  35. package/lib/download/npm/index.mjs +12 -8
  36. package/lib/download/npm/version.cjs +4 -2
  37. package/lib/download/npm/version.mjs +4 -2
  38. package/lib/export/directory.d.ts +1 -1
  39. package/lib/export/helpers/types-version.cjs +3 -1
  40. package/lib/export/helpers/types-version.mjs +3 -1
  41. package/lib/export/icon-package.d.ts +1 -1
  42. package/lib/export/json-package.cjs +13 -3
  43. package/lib/export/json-package.d.ts +1 -1
  44. package/lib/export/json-package.mjs +13 -3
  45. package/lib/icon-set/index.cjs +20 -8
  46. package/lib/icon-set/index.d.ts +1 -1
  47. package/lib/icon-set/index.mjs +20 -8
  48. package/lib/icon-set/match.d.ts +1 -1
  49. package/lib/icon-set/merge.d.ts +1 -1
  50. package/lib/icon-set/modified.d.ts +1 -1
  51. package/lib/icon-set/props.d.ts +1 -1
  52. package/lib/icon-set/tags.cjs +97 -0
  53. package/lib/icon-set/tags.d.ts +22 -0
  54. package/lib/icon-set/tags.mjs +91 -0
  55. package/lib/icon-set/types.d.ts +1 -1
  56. package/lib/import/directory.cjs +4 -1
  57. package/lib/import/directory.d.ts +1 -1
  58. package/lib/import/directory.mjs +4 -1
  59. package/lib/import/figma/index.cjs +5 -2
  60. package/lib/import/figma/index.d.ts +1 -1
  61. package/lib/import/figma/index.mjs +5 -2
  62. package/lib/import/figma/nodes.cjs +6 -2
  63. package/lib/import/figma/nodes.d.ts +2 -2
  64. package/lib/import/figma/nodes.mjs +6 -2
  65. package/lib/import/figma/query.cjs +29 -15
  66. package/lib/import/figma/query.d.ts +1 -1
  67. package/lib/import/figma/query.mjs +29 -15
  68. package/lib/import/figma/types/nodes.d.ts +1 -1
  69. package/lib/import/figma/types/options.d.ts +1 -1
  70. package/lib/import/figma/types/result.d.ts +1 -1
  71. package/lib/index.cjs +6 -3
  72. package/lib/index.d.ts +3 -1
  73. package/lib/index.mjs +4 -3
  74. package/lib/misc/compare-dirs.cjs +3 -1
  75. package/lib/misc/compare-dirs.mjs +3 -1
  76. package/lib/misc/exec.cjs +7 -8
  77. package/lib/misc/exec.mjs +7 -8
  78. package/lib/misc/keyword.cjs +4 -1
  79. package/lib/misc/keyword.mjs +4 -1
  80. package/lib/misc/scan.cjs +3 -1
  81. package/lib/misc/scan.mjs +3 -1
  82. package/lib/optimise/flags.cjs +9 -3
  83. package/lib/optimise/flags.d.ts +1 -1
  84. package/lib/optimise/flags.mjs +9 -3
  85. package/lib/optimise/global-style.cjs +10 -3
  86. package/lib/optimise/global-style.d.ts +1 -1
  87. package/lib/optimise/global-style.mjs +10 -3
  88. package/lib/optimise/scale.d.ts +1 -1
  89. package/lib/optimise/svgo.d.ts +1 -1
  90. package/lib/svg/analyse.cjs +20 -6
  91. package/lib/svg/analyse.d.ts +1 -1
  92. package/lib/svg/analyse.mjs +20 -6
  93. package/lib/svg/cleanup/attribs.d.ts +1 -1
  94. package/lib/svg/cleanup/bad-tags.cjs +7 -2
  95. package/lib/svg/cleanup/bad-tags.d.ts +1 -1
  96. package/lib/svg/cleanup/bad-tags.mjs +7 -2
  97. package/lib/svg/cleanup/inline-style.cjs +12 -4
  98. package/lib/svg/cleanup/inline-style.d.ts +1 -1
  99. package/lib/svg/cleanup/inline-style.mjs +12 -4
  100. package/lib/svg/cleanup/root-style.d.ts +1 -1
  101. package/lib/svg/cleanup/root-svg.d.ts +1 -1
  102. package/lib/svg/cleanup/svgo-style.d.ts +1 -1
  103. package/lib/svg/cleanup.d.ts +1 -1
  104. package/lib/svg/data/attributes.cjs +0 -1
  105. package/lib/svg/data/attributes.mjs +0 -1
  106. package/lib/svg/index.cjs +12 -3
  107. package/lib/svg/index.d.ts +2 -2
  108. package/lib/svg/index.mjs +12 -3
  109. package/lib/svg/parse-style.cjs +13 -8
  110. package/lib/svg/parse-style.d.ts +1 -1
  111. package/lib/svg/parse-style.mjs +13 -8
  112. package/lib/svg/parse.d.ts +1 -1
  113. package/package.json +23 -8
  114. package/lib/types-6360d61e.d.ts +0 -261
@@ -47,122 +47,146 @@ function getTokens(css) {
47
47
  }
48
48
  throw css_parser_error.styleParseError("Invalid css rule", css, textQueue[0]?.index);
49
49
  };
50
- findTokens(css, ['"', "'", "/*", "{", "}", ";", "url(", "\\"]).forEach((token) => {
51
- if (token.index < start) {
52
- return;
53
- }
54
- switch (token.token) {
55
- case "/*": {
56
- textQueue.push({
57
- type: "chunk",
58
- text: css.slice(start, token.index),
59
- index: start
60
- });
61
- start = token.index;
62
- const end = css.indexOf("*/", start + 2);
63
- if (end === -1) {
64
- throw css_parser_error.styleParseError("Missing comment closing statement", css, start);
65
- }
66
- start = end + 2;
67
- break;
50
+ findTokens(css, ['"', "'", "/*", "{", "}", ";", "url(", "\\"]).forEach(
51
+ (token) => {
52
+ if (token.index < start) {
53
+ return;
68
54
  }
69
- case "\\":
70
- textQueue.push({
71
- type: "chunk",
72
- text: css.slice(start, token.index + 2),
73
- index: start
74
- });
75
- start = token.index + 2;
76
- break;
77
- case "url(": {
78
- textQueue.push({
79
- type: "chunk",
80
- text: css.slice(start, token.index),
81
- index: start
82
- });
83
- start = token.index;
84
- const end = css_parser_strings.findEndOfURL(css, start);
85
- if (typeof end !== "number") {
86
- throw end;
55
+ switch (token.token) {
56
+ case "/*": {
57
+ textQueue.push({
58
+ type: "chunk",
59
+ text: css.slice(start, token.index),
60
+ index: start
61
+ });
62
+ start = token.index;
63
+ const end = css.indexOf("*/", start + 2);
64
+ if (end === -1) {
65
+ throw css_parser_error.styleParseError(
66
+ "Missing comment closing statement",
67
+ css,
68
+ start
69
+ );
70
+ }
71
+ start = end + 2;
72
+ break;
87
73
  }
88
- textQueue.push({
89
- type: "url",
90
- text: css.slice(start, end),
91
- index: start
92
- });
93
- start = end;
94
- break;
95
- }
96
- case '"':
97
- case "'": {
98
- textQueue.push({
99
- type: "chunk",
100
- text: css.slice(start, token.index),
101
- index: start
102
- });
103
- start = token.index;
104
- const end = css_parser_strings.findEndOfQuotedString(css, token.token, start);
105
- if (end === null) {
106
- throw css_parser_error.styleParseError("Missing closing " + token.token, css, start);
74
+ case "\\":
75
+ textQueue.push({
76
+ type: "chunk",
77
+ text: css.slice(start, token.index + 2),
78
+ index: start
79
+ });
80
+ start = token.index + 2;
81
+ break;
82
+ case "url(": {
83
+ textQueue.push({
84
+ type: "chunk",
85
+ text: css.slice(start, token.index),
86
+ index: start
87
+ });
88
+ start = token.index;
89
+ const end = css_parser_strings.findEndOfURL(css, start);
90
+ if (typeof end !== "number") {
91
+ throw end;
92
+ }
93
+ textQueue.push({
94
+ type: "url",
95
+ text: css.slice(start, end),
96
+ index: start
97
+ });
98
+ start = end;
99
+ break;
107
100
  }
108
- textQueue.push({
109
- type: "quoted-string",
110
- text: css.slice(start, end),
111
- index: start
112
- });
113
- start = end;
114
- break;
115
- }
116
- case ";": {
117
- textQueue.push({
118
- type: "chunk",
119
- text: css.slice(start, token.index),
120
- index: start
121
- });
122
- checkRule(token.token);
123
- start = token.index + 1;
124
- textQueue = [];
125
- break;
126
- }
127
- case "{": {
128
- textQueue.push({
129
- type: "chunk",
130
- text: css.slice(start, token.index),
131
- index: start
132
- });
133
- const item = css_parser_text.textTokensToSelector(textQueue);
134
- if (!item) {
135
- throw css_parser_error.styleParseError("Invalid css rule", css, start);
101
+ case '"':
102
+ case "'": {
103
+ textQueue.push({
104
+ type: "chunk",
105
+ text: css.slice(start, token.index),
106
+ index: start
107
+ });
108
+ start = token.index;
109
+ const end = css_parser_strings.findEndOfQuotedString(
110
+ css,
111
+ token.token,
112
+ start
113
+ );
114
+ if (end === null) {
115
+ throw css_parser_error.styleParseError(
116
+ "Missing closing " + token.token,
117
+ css,
118
+ start
119
+ );
120
+ }
121
+ textQueue.push({
122
+ type: "quoted-string",
123
+ text: css.slice(start, end),
124
+ index: start
125
+ });
126
+ start = end;
127
+ break;
136
128
  }
137
- items.push(item);
138
- start = token.index + 1;
139
- textQueue = [];
140
- depth++;
141
- break;
142
- }
143
- case "}": {
144
- textQueue.push({
145
- type: "chunk",
146
- text: css.slice(start, token.index),
147
- index: start
148
- });
149
- checkRule("");
150
- items.push({
151
- type: "close",
152
- index: token.index
153
- });
154
- if (!depth) {
155
- throw css_parser_error.styleParseError("Unexpected }", css, token.index);
129
+ case ";": {
130
+ textQueue.push({
131
+ type: "chunk",
132
+ text: css.slice(start, token.index),
133
+ index: start
134
+ });
135
+ checkRule(token.token);
136
+ start = token.index + 1;
137
+ textQueue = [];
138
+ break;
139
+ }
140
+ case "{": {
141
+ textQueue.push({
142
+ type: "chunk",
143
+ text: css.slice(start, token.index),
144
+ index: start
145
+ });
146
+ const item = css_parser_text.textTokensToSelector(textQueue);
147
+ if (!item) {
148
+ throw css_parser_error.styleParseError(
149
+ "Invalid css rule",
150
+ css,
151
+ start
152
+ );
153
+ }
154
+ items.push(item);
155
+ start = token.index + 1;
156
+ textQueue = [];
157
+ depth++;
158
+ break;
156
159
  }
157
- depth--;
158
- start = token.index + 1;
159
- textQueue = [];
160
- break;
160
+ case "}": {
161
+ textQueue.push({
162
+ type: "chunk",
163
+ text: css.slice(start, token.index),
164
+ index: start
165
+ });
166
+ checkRule("");
167
+ items.push({
168
+ type: "close",
169
+ index: token.index
170
+ });
171
+ if (!depth) {
172
+ throw css_parser_error.styleParseError(
173
+ "Unexpected }",
174
+ css,
175
+ token.index
176
+ );
177
+ }
178
+ depth--;
179
+ start = token.index + 1;
180
+ textQueue = [];
181
+ break;
182
+ }
183
+ default:
184
+ throw new Error(
185
+ `Forgot to parse token: ${token.token}`
186
+ );
161
187
  }
162
- default:
163
- throw new Error(`Forgot to parse token: ${token.token}`);
164
188
  }
165
- });
189
+ );
166
190
  if (depth) {
167
191
  return css_parser_error.styleParseError("Missing }", css);
168
192
  }
@@ -43,122 +43,146 @@ function getTokens(css) {
43
43
  }
44
44
  throw styleParseError("Invalid css rule", css, textQueue[0]?.index);
45
45
  };
46
- findTokens(css, ['"', "'", "/*", "{", "}", ";", "url(", "\\"]).forEach((token) => {
47
- if (token.index < start) {
48
- return;
49
- }
50
- switch (token.token) {
51
- case "/*": {
52
- textQueue.push({
53
- type: "chunk",
54
- text: css.slice(start, token.index),
55
- index: start
56
- });
57
- start = token.index;
58
- const end = css.indexOf("*/", start + 2);
59
- if (end === -1) {
60
- throw styleParseError("Missing comment closing statement", css, start);
61
- }
62
- start = end + 2;
63
- break;
46
+ findTokens(css, ['"', "'", "/*", "{", "}", ";", "url(", "\\"]).forEach(
47
+ (token) => {
48
+ if (token.index < start) {
49
+ return;
64
50
  }
65
- case "\\":
66
- textQueue.push({
67
- type: "chunk",
68
- text: css.slice(start, token.index + 2),
69
- index: start
70
- });
71
- start = token.index + 2;
72
- break;
73
- case "url(": {
74
- textQueue.push({
75
- type: "chunk",
76
- text: css.slice(start, token.index),
77
- index: start
78
- });
79
- start = token.index;
80
- const end = findEndOfURL(css, start);
81
- if (typeof end !== "number") {
82
- throw end;
51
+ switch (token.token) {
52
+ case "/*": {
53
+ textQueue.push({
54
+ type: "chunk",
55
+ text: css.slice(start, token.index),
56
+ index: start
57
+ });
58
+ start = token.index;
59
+ const end = css.indexOf("*/", start + 2);
60
+ if (end === -1) {
61
+ throw styleParseError(
62
+ "Missing comment closing statement",
63
+ css,
64
+ start
65
+ );
66
+ }
67
+ start = end + 2;
68
+ break;
83
69
  }
84
- textQueue.push({
85
- type: "url",
86
- text: css.slice(start, end),
87
- index: start
88
- });
89
- start = end;
90
- break;
91
- }
92
- case '"':
93
- case "'": {
94
- textQueue.push({
95
- type: "chunk",
96
- text: css.slice(start, token.index),
97
- index: start
98
- });
99
- start = token.index;
100
- const end = findEndOfQuotedString(css, token.token, start);
101
- if (end === null) {
102
- throw styleParseError("Missing closing " + token.token, css, start);
70
+ case "\\":
71
+ textQueue.push({
72
+ type: "chunk",
73
+ text: css.slice(start, token.index + 2),
74
+ index: start
75
+ });
76
+ start = token.index + 2;
77
+ break;
78
+ case "url(": {
79
+ textQueue.push({
80
+ type: "chunk",
81
+ text: css.slice(start, token.index),
82
+ index: start
83
+ });
84
+ start = token.index;
85
+ const end = findEndOfURL(css, start);
86
+ if (typeof end !== "number") {
87
+ throw end;
88
+ }
89
+ textQueue.push({
90
+ type: "url",
91
+ text: css.slice(start, end),
92
+ index: start
93
+ });
94
+ start = end;
95
+ break;
103
96
  }
104
- textQueue.push({
105
- type: "quoted-string",
106
- text: css.slice(start, end),
107
- index: start
108
- });
109
- start = end;
110
- break;
111
- }
112
- case ";": {
113
- textQueue.push({
114
- type: "chunk",
115
- text: css.slice(start, token.index),
116
- index: start
117
- });
118
- checkRule(token.token);
119
- start = token.index + 1;
120
- textQueue = [];
121
- break;
122
- }
123
- case "{": {
124
- textQueue.push({
125
- type: "chunk",
126
- text: css.slice(start, token.index),
127
- index: start
128
- });
129
- const item = textTokensToSelector(textQueue);
130
- if (!item) {
131
- throw styleParseError("Invalid css rule", css, start);
97
+ case '"':
98
+ case "'": {
99
+ textQueue.push({
100
+ type: "chunk",
101
+ text: css.slice(start, token.index),
102
+ index: start
103
+ });
104
+ start = token.index;
105
+ const end = findEndOfQuotedString(
106
+ css,
107
+ token.token,
108
+ start
109
+ );
110
+ if (end === null) {
111
+ throw styleParseError(
112
+ "Missing closing " + token.token,
113
+ css,
114
+ start
115
+ );
116
+ }
117
+ textQueue.push({
118
+ type: "quoted-string",
119
+ text: css.slice(start, end),
120
+ index: start
121
+ });
122
+ start = end;
123
+ break;
132
124
  }
133
- items.push(item);
134
- start = token.index + 1;
135
- textQueue = [];
136
- depth++;
137
- break;
138
- }
139
- case "}": {
140
- textQueue.push({
141
- type: "chunk",
142
- text: css.slice(start, token.index),
143
- index: start
144
- });
145
- checkRule("");
146
- items.push({
147
- type: "close",
148
- index: token.index
149
- });
150
- if (!depth) {
151
- throw styleParseError("Unexpected }", css, token.index);
125
+ case ";": {
126
+ textQueue.push({
127
+ type: "chunk",
128
+ text: css.slice(start, token.index),
129
+ index: start
130
+ });
131
+ checkRule(token.token);
132
+ start = token.index + 1;
133
+ textQueue = [];
134
+ break;
135
+ }
136
+ case "{": {
137
+ textQueue.push({
138
+ type: "chunk",
139
+ text: css.slice(start, token.index),
140
+ index: start
141
+ });
142
+ const item = textTokensToSelector(textQueue);
143
+ if (!item) {
144
+ throw styleParseError(
145
+ "Invalid css rule",
146
+ css,
147
+ start
148
+ );
149
+ }
150
+ items.push(item);
151
+ start = token.index + 1;
152
+ textQueue = [];
153
+ depth++;
154
+ break;
152
155
  }
153
- depth--;
154
- start = token.index + 1;
155
- textQueue = [];
156
- break;
156
+ case "}": {
157
+ textQueue.push({
158
+ type: "chunk",
159
+ text: css.slice(start, token.index),
160
+ index: start
161
+ });
162
+ checkRule("");
163
+ items.push({
164
+ type: "close",
165
+ index: token.index
166
+ });
167
+ if (!depth) {
168
+ throw styleParseError(
169
+ "Unexpected }",
170
+ css,
171
+ token.index
172
+ );
173
+ }
174
+ depth--;
175
+ start = token.index + 1;
176
+ textQueue = [];
177
+ break;
178
+ }
179
+ default:
180
+ throw new Error(
181
+ `Forgot to parse token: ${token.token}`
182
+ );
157
183
  }
158
- default:
159
- throw new Error(`Forgot to parse token: ${token.token}`);
160
184
  }
161
- });
185
+ );
162
186
  if (depth) {
163
187
  return styleParseError("Missing }", css);
164
188
  }
@@ -18,15 +18,16 @@ function apiCacheKey(query) {
18
18
  }
19
19
  async function storeAPICache(options, key, data) {
20
20
  const expires = Date.now() + options.ttl * 1e3;
21
- const filename = options.dir + "/" + key + "." + expires + ".json";
21
+ const filename = options.dir + "/" + key + "." + expires.toString() + ".json";
22
22
  if (!storedFiles[options.dir]) {
23
23
  await getStoredFiles(options.dir);
24
24
  }
25
- await fs.promises.writeFile(filename, JSON.stringify({
25
+ const content = {
26
26
  version: cacheVersion,
27
27
  expires,
28
28
  data
29
- }, null, 4), "utf8");
29
+ };
30
+ await fs.promises.writeFile(filename, JSON.stringify(content, null, 4), "utf8");
30
31
  storedFiles[options.dir][key] = {
31
32
  filename,
32
33
  expires
@@ -42,7 +43,9 @@ async function getAPICache(dir, key) {
42
43
  }
43
44
  const time = Date.now();
44
45
  try {
45
- const content = JSON.parse(await fs.promises.readFile(item.filename, "utf8"));
46
+ const content = JSON.parse(
47
+ await fs.promises.readFile(item.filename, "utf8")
48
+ );
46
49
  return content.version === cacheVersion && content.expires > time ? content.data : null;
47
50
  } catch (err) {
48
51
  return null;
@@ -61,23 +64,27 @@ async function getStoredFiles(dir, clear = false) {
61
64
  });
62
65
  } catch (err) {
63
66
  }
64
- await misc_scan.scanDirectory(dir, async (ext, file, subdir, path) => {
65
- if (ext !== ".json") {
66
- return false;
67
- }
68
- const filename = path + subdir + file + ext;
69
- const parts = file.split(".");
70
- const expires = parseInt(parts.pop());
71
- if (clear || expires < time || parts.length !== 1) {
72
- await fs.promises.unlink(filename);
73
- return false;
74
- }
75
- const cacheKey = parts[0];
76
- storage[cacheKey] = {
77
- filename,
78
- expires
79
- };
80
- }, false);
67
+ await misc_scan.scanDirectory(
68
+ dir,
69
+ async (ext, file, subdir, path) => {
70
+ if (ext !== ".json") {
71
+ return false;
72
+ }
73
+ const filename = path + subdir + file + ext;
74
+ const parts = file.split(".");
75
+ const expires = parseInt(parts.pop());
76
+ if (clear || expires < time || parts.length !== 1) {
77
+ await fs.promises.unlink(filename);
78
+ return false;
79
+ }
80
+ const cacheKey = parts[0];
81
+ storage[cacheKey] = {
82
+ filename,
83
+ expires
84
+ };
85
+ },
86
+ false
87
+ );
81
88
  }
82
89
 
83
90
  exports.apiCacheKey = apiCacheKey;
@@ -14,15 +14,16 @@ function apiCacheKey(query) {
14
14
  }
15
15
  async function storeAPICache(options, key, data) {
16
16
  const expires = Date.now() + options.ttl * 1e3;
17
- const filename = options.dir + "/" + key + "." + expires + ".json";
17
+ const filename = options.dir + "/" + key + "." + expires.toString() + ".json";
18
18
  if (!storedFiles[options.dir]) {
19
19
  await getStoredFiles(options.dir);
20
20
  }
21
- await promises.writeFile(filename, JSON.stringify({
21
+ const content = {
22
22
  version: cacheVersion,
23
23
  expires,
24
24
  data
25
- }, null, 4), "utf8");
25
+ };
26
+ await promises.writeFile(filename, JSON.stringify(content, null, 4), "utf8");
26
27
  storedFiles[options.dir][key] = {
27
28
  filename,
28
29
  expires
@@ -38,7 +39,9 @@ async function getAPICache(dir, key) {
38
39
  }
39
40
  const time = Date.now();
40
41
  try {
41
- const content = JSON.parse(await promises.readFile(item.filename, "utf8"));
42
+ const content = JSON.parse(
43
+ await promises.readFile(item.filename, "utf8")
44
+ );
42
45
  return content.version === cacheVersion && content.expires > time ? content.data : null;
43
46
  } catch (err) {
44
47
  return null;
@@ -57,23 +60,27 @@ async function getStoredFiles(dir, clear = false) {
57
60
  });
58
61
  } catch (err) {
59
62
  }
60
- await scanDirectory(dir, async (ext, file, subdir, path) => {
61
- if (ext !== ".json") {
62
- return false;
63
- }
64
- const filename = path + subdir + file + ext;
65
- const parts = file.split(".");
66
- const expires = parseInt(parts.pop());
67
- if (clear || expires < time || parts.length !== 1) {
68
- await promises.unlink(filename);
69
- return false;
70
- }
71
- const cacheKey = parts[0];
72
- storage[cacheKey] = {
73
- filename,
74
- expires
75
- };
76
- }, false);
63
+ await scanDirectory(
64
+ dir,
65
+ async (ext, file, subdir, path) => {
66
+ if (ext !== ".json") {
67
+ return false;
68
+ }
69
+ const filename = path + subdir + file + ext;
70
+ const parts = file.split(".");
71
+ const expires = parseInt(parts.pop());
72
+ if (clear || expires < time || parts.length !== 1) {
73
+ await promises.unlink(filename);
74
+ return false;
75
+ }
76
+ const cacheKey = parts[0];
77
+ storage[cacheKey] = {
78
+ filename,
79
+ expires
80
+ };
81
+ },
82
+ false
83
+ );
77
84
  }
78
85
 
79
86
  export { apiCacheKey, clearAPICache, getAPICache, storeAPICache };