From 49f4eaf2417437b32ae2db22ebe66dbb0f2abffa Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Fri, 2 Dec 2016 09:37:30 +0100 Subject: [PATCH] updated alias --- index.js | 18 +++++++++++++----- readme.md | 5 ++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 4ce1613..36f7ef4 100644 --- a/index.js +++ b/index.js @@ -8,15 +8,23 @@ var jsonExtra = module.exports = { } function doRequire(name, alias) { - if (alias){ + jsonExtra[name] = require('./lib/' + name); + + if (alias) { + if (Object.prototype.toString.call(alias) === '[object Array]') { + for (var aka in alias) { + jsonExtra[aka] = require('./lib/' + name); + } + + return + } + return jsonExtra[alias] = require('./lib/' + name); } - - return jsonExtra[name] = require('./lib/' + name); } -doRequire('check'); -doRequire('toPath'); +doRequire('check', ['isJson', 'isValid']); +doRequire('toPath', 'chain'); doRequire('readToObj'); doRequire('readToObjSync'); doRequire('create'); diff --git a/readme.md b/readme.md index 61a3394..e8ccb21 100644 --- a/readme.md +++ b/readme.md @@ -47,9 +47,10 @@ var json = require('json-extra'); Check if it is a valid string or object. Just do a `JSON.parse` but with `try - catch`. Returns a boolean. The `type` is optional it its default is `string`. If you want to check if you have a object you can type in `object` as `type`. -`type` valid values: `string` or `object` +`type` valid values: `string` or `object`. Default: `string` Alias: `isJson()` +Alias: `isValid()` Example: @@ -68,6 +69,8 @@ If you want to change your json string into a path just hit this method. `base` in an object is always the name of the folder. `subfolders` create new subfolders +Alias: `chain()` + Example: ```js