(filePath: string, width: number)
| 228 | }; |
| 229 | |
| 230 | const toAsset = async (filePath: string, width: number): Promise<Asset> => { |
| 231 | const image = sharp(filePath); |
| 232 | const { format } = await image.metadata(); |
| 233 | |
| 234 | if (format !== "png" && format !== "svg") { |
| 235 | log.error( |
| 236 | `${path.basename(filePath)} image file format (${format}) is not supported`, |
| 237 | ); |
| 238 | process.exit(1); |
| 239 | } |
| 240 | |
| 241 | const [height, hash] = await Promise.all([ |
| 242 | image |
| 243 | .clone() |
| 244 | .resize(width) |
| 245 | .toBuffer() |
| 246 | .then((buffer) => sharp(buffer).metadata()) |
| 247 | .then(({ height = 0 }) => Math.round(height)), |
| 248 | |
| 249 | image |
| 250 | .clone() |
| 251 | .resize(width) |
| 252 | .png({ quality: 100 }) |
| 253 | .toBuffer() |
| 254 | .then((buffer) => buffer.toString("base64")), |
| 255 | ]); |
| 256 | |
| 257 | return { |
| 258 | path: filePath, |
| 259 | image, |
| 260 | hash, |
| 261 | height, |
| 262 | width, |
| 263 | }; |
| 264 | }; |
| 265 | |
| 266 | const parseColor = (value: string) => { |
| 267 | const up = value.toUpperCase().replace(/[^0-9A-F]/g, ""); |
no outgoing calls
no test coverage detected
searching dependent graphs…