req-prop

0.1.1 • Public • Published

req-prop Build Status

Easy require property from cwd. Get, extend, destroy property using dot-notation

Install

$ npm install --save req-prop

Usage

Imagine the folder structure like this.

├── code
│   └── dev-app
│   │   ├── config/setting.js
│   │   ├── lib/database/api/v1/index.js
│   │   ├── index.js
│   │   └── package.json
// ~/code/dev-app/config/setting.js
module.exports = {
    app: {
        name: 'unicorn'
    }
};
// ~/code/dev-app/lib/database/api/v1/index.js
const reqProp = require('req-prop');
 
const setting = reqProp('api', './config/setting');
 
console.log(setting.get('api.app.name'));
# ~/code/dev-app 
$ node lib/database/api/v1/index.js
# 'unicorn' 

API

reqProp(key, moduleId)

key

  • Type string
  • Required: true

moduleId

  • Type string
  • Required: true

Set Module path

Instance

Also See dot-prop API

.extend(key, value)

Extend an item.

.extend(object)

Extend multiple items at once.

.get(key)

Get an item.

.has(key)

Check if an item exists.

.destroy(key)

Delete an item.

.clear()

Delete all items.

License

MIT © Guntur Poetra

Readme

Keywords

Package Sidebar

Install

npm i req-prop

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • guntur