MCPcopy
hub / github.com/zoontek/react-native-bootsplash / toAsset

Function toAsset

src/extras/utils.ts:230–264  ·  view source on GitHub ↗
(filePath: string, width: number)

Source from the content-addressed store, hash-verified

228};
229
230const 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
266const parseColor = (value: string) => {
267 const up = value.toUpperCase().replace(/[^0-9A-F]/g, "");

Callers 1

transformPropsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…