Skip to content

iguntur/req-prop

Repository files navigation

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

About

Require property from `cwd`. Get, extend, destroy property using dot-notation

Resources

License

Stars

Watchers

Forks

Packages

No packages published