es-dep-kit
v1.0.1
Published
ECMAScript 2015+/CommonJS module dependencies helpers kit
Downloads
2
Maintainers
Readme
es-dep-kit
ECMAScript 2015+/CommonJS module dependencies helpers kit
Install
npm install --save es-dep-kit
API
Every function requires one dep
argument — Object
described by es-dep-unit.
Helpers
_requested
— returnsdep.requested
_from
— returnsdep.from
_resolved
— returnsdep.resolved
Methods
isEntry
— true ifdep.requested
isnull
isRequestedPackage
— true ifdep.requested
is not a local fileisRequestedLocalFile
— true ifdep.requested
is a local fileisResolvedInNM
— true ifdep.resolved
containsnode_modules
isRequestedFromNM
— true ifdep.from
containsnode_modules
isResolved
— true ifdep.resolved
is notnull
isNotResolved
— true ifdep.resolved
isnull
isThirdParty
— true ifdep
is not direct dependency: not local file and notpackage
being requested from local file
Usage
import kit from 'es-dep-kit';
import { esDepUnit as dep } from 'es-dep-unit';
// arguments are `requested`, `from` and `resolved` respectively
// if string is relative path, it will be prepended with `process.cwd()`
const entry = dep(null, null, 'index.js');
const file = dep('./file', 'index.js', 'file.js');
const fileExtra = dep('./file-extra', 'index.js', null);
const pkg = dep('pkg', 'index.js', 'node_modules/pkg/index.js');
const pkgExtra = dep('pkg-extra', 'index.js', null);
const pkgFile = dep('./pkg-file', 'node_modules/pkg/index.js', 'node_modules/pkg/file.js'); // eslint-disable-line
const pkgFileExtra = dep('./pkg-file-extra', 'node_modules/pkg/index.js', null);
const nestedPkg = dep('nested-pkg', 'node_modules/pkg/index.js', 'node_modules/pkg/node_modules/nested-pkg/index.js'); // eslint-disable-line
const nestedPkgExtra = dep('nested-pkg-extra', 'node_modules/pkg/index.js', null);
const nestedPkgFile = dep('./nested-pkg-file', 'node_modules/pkg/node_modules/nested-pkg/index.js', 'node_modules/pkg/node_modules/nested-pkg/file.js'); // eslint-disable-line
const nestedPkgFileExtra = dep('./nested-pkg-file-extra', 'node_modules/pkg/node_modules/nested-pkg/index.js', null); // eslint-disable-line
kit._requested(file); // ./file
kit._resolved(file); // /Users/iamstarkov/projects/es-dep-kit/file.js
kit._from(file); // /Users/iamstarkov/projects/es-dep-kit/index.js
kit.isEntry(entry); // true
kit.isEntry(file); // false
kit.isRequestedPackage(file); // false
kit.isRequestedPackage(pkg); // true
kit.isRequestedLocalFile(file); // true
kit.isRequestedLocalFile(pkg); // false
kit.isRequestedLocalFile(pkgFile); // true
kit.isRequestedLocalFile(nestedPkg); // false
kit.isResolvedInNM(file); // false
kit.isResolvedInNM(pkg); // true
kit.isResolvedInNM(pkgExtra); // false
kit.isRequestedFromNM(file); // false
kit.isRequestedFromNM(pkg); // false
kit.isRequestedFromNM(nestedPkg); // true
kit.isResolved(file); // true
kit.isNotResolved(fileExtra); // true
kit.isThirdParty(file); // false
kit.isThirdParty(pkg); // false
kit.isThirdParty(pkgFile); // true
kit.isThirdParty(nestedPkg); // true
kit.isThirdParty(nestedPkgFile); // true
Related
- es-deps — ECMAScript 2015+/CommonJS module dependencies array
- es-deps-from-string — ECMAScript 2015+/CommonJS module dependencies array from string
- es-deps-resolved — ECMAScript 2015+/CommonJS module dependencies resolved array
- es-dep-unit — Constructor for ECMAScript 2015+/CommonJS dependency unit
Object { requested, from, resolved }
- es-deps-deep — ECMAScript 2015+/CommonJS module dependencies resolved in depth
License
MIT © Vladimir Starkov