GithubHelp home page GithubHelp logo

adelarmand / parent-modules Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hastijs/parent-modules

1.0 0.0 0.0 7 KB

Get all parent modules including the module which our script lives in.

License: MIT License

JavaScript 100.00%

parent-modules's Introduction

Parent Modules

Get all parent modules

Useful when you want to get all parent modules including the module which your script lives in.

Install

$ npm install parent-modules --save

Know more

Assume that we have three nested modules into /home/hastijs directory. That means we require module three into module two and module two into module one.

/home/hastijs/
|_ module-one.js
   |_ module-two.js
      |_ module-three.js

Now we run module-one while parent-modules called into module-three.

// module-three.js
console.log(require('parent-modules')());

The result is:

//=> [ '/home/hastijs/module-three.js', '/home/hastijs/module-two.js', '/home/hastijs/module-one.js' ]

Usage

In all examples bellow, module-one executed.

Get parents IDs

// module-two.js (path: /home/hastijs/module-two.js)
const parentModules = require('parent-modules');
console.log(parentModules());
// module-one.js (path: /home/hastijs/module-one.js)
require('./module-two');
//=> [ '/home/hastijs/module-two.js', '/home/hastijs/module-one.js' ]

Get parents names

// module-two.js (path: /home/hastijs/module-two.js)
const parentModules = require('parent-modules');
const options = {type: 'names'};
console.log(parentModules(options));
// module-one.js (path: /home/hastijs/module-one.js)
require('./module-two');
//=> [ 'module-tow', 'module-one' ]

Get parents names by index

// module-three.js (path: /home/hastijs/module-three.js)
const parentModules = require('parent-modules');
const options = {type: 'names', indexes: [0, 2]};
console.log(parentModules(options));
// module-two.js (path: /home/hastijs/module-tow.js)
require('./module-three');
// module-one.js (path: /home/hastijs/module-one.js)
require('./module-two');
//=> [ 'module-three', 'module-one' ]

Search and get parents name->id (complex) into an index range

// module-three.js (path: /home/hastijs/module-three.js)
const parentModules = require('parent-modules');
const options = {type: 'complex', find: /module-t/, indexRange: [1, 2]};
console.log(parentModules(options));
// module-two.js (path: /home/hastijs/module-tow.js)
require('./module-three');
// module-one.js (path: /home/hastijs/module-one.js)
require('./module-two');
//=> [ 'module-two': '/home/hastijs/module-tow.js' ]

API

parentModules(options)

options

Type: object

Options to filter result (parent modules).

type

Type: string

Default: ids

You can use ids, names and complex.

find

Type: string | object

Search the result using a string or RegExp.

indexes

Type: array

List of parent module indexes which we want to get.

indexRange

Type: array

Range of parent module indexes which we want to get.

Contributing

Everyone is very welcome to contribute to Parent Modules project. Parent Modules is a HastiJS project so please see HastiJS contributing guidelines before contributing.

License

MIT © HastiJS

parent-modules's People

Contributors

adelarmand avatar theyahya avatar

Stargazers

Roman 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.