npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-images-saver

v1.4.0

Published

Save to files all base64 images contained in the json

Downloads

9

Readme

json-images-saver

npm version

Save to files all base64 images contained in the json

It can be easily integrated with the output of static site creator

Features

  • [x] gulp support (with multiple json files support)
  • [ ] gulp steam support
  • [x] laravel elixir support
  • [x] support of angular-base64-upload export (default options)
  • [x] custom base 64 pattern
  • [x] any name support
  • [ ] any name support for multiple keys
  • [x] delete old images as option (in gulp version)

TODO

  • [ ] test wrong cases for base64_structure
  • [ ] travis integration
  • [ ] elixir notify
  • [ ] remove old dir when dir name is changed

Examples

Elixir

"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});
});

Elixir with pug

"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);
    }
});
  • locked is used in pug file to lock the compilation until the json is ready, this way is needed because we have to call elixir-pug at the begining to initialize it (to create the gulp task)
  • the timeout is needed to start jsonImagesSaver the first time, to have data to pass pug (they are stored only in the memory)