Giter Site home page Giter Site logo

json2dir's Introduction

json2dir

CI

  • Convert JSON object to directory tree
  • Auto mkdir recursively
  • Zero dependencies
  • Lightweight ~1 KB

Install

npm install json2dir

Types

json2dir(
    dir: string,
    serializers: Record<string, (obj: any) => string>,
    obj: any
) : void

Usage

import json2dir from 'json2dir'
import ini from 'ini'

const bob = { name: 'Bob', age: 23 }

json2dir(
    '/root',
    {
        '.ini': ini.encode,
        '.json': JSON.stringify
    },
    {
        'a.json': bob,
        'b.ini': { INFO: bob },
        c: { d: { 'e.json': bob } },
        '.sub/foo.bar/f.json': bob
    }
)

Results

/root
│   a.json
│   b.json
│
└───c/d
│   │
│   │   e.json
│
└───.sub/foo.bar
    │
    │   f.json

Exceptions

If serializer is not provided, an exception will occur. For example: Error: No serializer for extension '.json'

Sponsor

Buy Me A Coffee

json2dir's People

Contributors

chientrm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.