
Security News
Static vs. Runtime Reachability: Insights from Latio’s On the Record Podcast
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
json-images-saver
Advanced tools
Save to files all base64 images contained in the json
It can be easily integrated with the output of static site creator
"use strict";
var elixir = require('laravel-elixir');
require('laravel-elixir-pug');
var gulp = require('gulp');
elixir(function (mix) {
mix.jsonImagesSaver('data/**/*.json',()=>gulp.dest('out'),'json',{images_path:__dirname+'/public/img/data/', delete_files:true});
});
"use strict";
var elixir = require('laravel-elixir');
require('laravel-elixir-pug');
require('json-images-saver/elixir');
var fs = require('fs');
var gulp = require('gulp');
var through = require('through2');
var args = require('yargs').argv;
class JsonCollection{
constructor() {
this._list = [];
this.data = {};
}
set(name, json){
if(!(name in this._list))
this.add(name);
try {
this._list[name] = JSON.parse(json.toString('utf-8'));
}catch(e){
this._list[name] = json.toString('utf-8');
}
}
add(name){
var _this = this;
Object.defineProperty(this.data, name, { get: function() { return _this._list[name]} , set: function(value){}, enumerable: true, configurable: true});
}
}
function jsonPipe() {
return function () {
// Creating a stream through which each file will pass
var stream = through.obj(function (file, enc, cb) {
if (file.isNull()) {
// return empty file
return cb(null, file);
}
if (file.isBuffer()) {
let name = file.path.split('/'); //TODO checks
name = name[name.length - 1];
jsonCollection.set(name.substr(0, name.length - ('json'.length + 1)), file.contents);
return cb(null, file);
}
if (file.isStream()) {
return cb(new PluginError(PLUGIN_NAME, 'Not yet supported'));
}
});
stream.on('end', function () {
pugVars.locked = false;
gulp.start('pug');
});
return stream;
}
}
var jsonCollection = new JsonCollection();
var pugVars = {locked:true};
elixir(function (mix) {
mix.jsonImagesSaver('data/**/*.json',jsonPipe(),'json',{images_path:__dirname+'/public/img/data/', delete_files:true})
.pug({
locals: {
data: jsonCollection,
pugVars: pugVars
},
});
if(args._.indexOf('watch') != -1) {
setTimeout(()=> {
fs.writeFile(__dirname + '/data/test.json', '{"time":"' + new Date().toTimeString() + '"}', function () {
});
}, 1000);
}
});
FAQs
Save to files all base64 images contained in the json
The npm package json-images-saver receives a total of 1 weekly downloads. As such, json-images-saver popularity was classified as not popular.
We found that json-images-saver demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.