json2dir
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

json2dir

CI Codacy Badge Codacy Badge

  • 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

Package Sidebar

Install

npm i json2dir

Weekly Downloads

2

Version

0.1.8

License

MIT

Unpacked Size

11.3 kB

Total Files

16

Last publish

Collaborators

  • chientrm