boxwood 0.71.2 → 0.72.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.
- package/index.js +31 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -431,6 +431,37 @@ const nodes = [
|
|
|
431
431
|
return result
|
|
432
432
|
}, {})
|
|
433
433
|
|
|
434
|
+
function extension(path) {
|
|
435
|
+
const parts = path.split(".")
|
|
436
|
+
return parts[parts.length - 1].toLowerCase()
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function media(path) {
|
|
440
|
+
const type = extension(path)
|
|
441
|
+
if (type === "svg") {
|
|
442
|
+
return "image/svg+xml"
|
|
443
|
+
}
|
|
444
|
+
return `image/${type === "jpg" ? "jpeg" : type}`
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function base64({ content, path }) {
|
|
448
|
+
return `data:${media(path)};base64,${content}`
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
nodes.img.load = function () {
|
|
452
|
+
const path = join(...arguments)
|
|
453
|
+
const content = readFileSync(path, "base64")
|
|
454
|
+
return (options) => {
|
|
455
|
+
return nodes.img({ src: base64({ content, path }), ...options })
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
nodes.svg.load = function () {
|
|
460
|
+
const path = join(...arguments)
|
|
461
|
+
const content = readFileSync(path, "utf8")
|
|
462
|
+
return raw(content)
|
|
463
|
+
}
|
|
464
|
+
|
|
434
465
|
function classes() {
|
|
435
466
|
const array = []
|
|
436
467
|
for (let i = 0, ilen = arguments.length; i < ilen; i += 1) {
|