Socket
Socket
Sign inDemoInstall

joycon

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joycon - npm Package Compare versions

Comparing version 2.1.2 to 2.2.0

165

lib/index.js

@@ -14,4 +14,2 @@ "use strict";

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
const readFile = fp => new Promise((resolve, reject) => {

@@ -61,39 +59,45 @@ _fs.default.readFile(fp, 'utf8', (err, data) => {

recusivelyResolve(options) {
var _this = this;
return _asyncToGenerator(function* () {
if (options.cwd === options.stopDir || _path.default.basename(options.cwd) === 'node_modules') {
return null;
removeLoader(name) {
for (const loader of this.loaders) {
if (name && loader.name === name) {
this.loaders.delete(loader);
}
}
for (const filename of options.files) {
const file = _path.default.resolve(options.cwd, filename);
return this;
}
let exists = process.env.NODE_ENV !== 'test' && _this.existsCache.has(file) ? _this.existsCache.get(file) : yield pathExists(file);
async recusivelyResolve(options) {
if (options.cwd === options.stopDir || _path.default.basename(options.cwd) === 'node_modules') {
return null;
}
if (exists && options.packageKey && _path.default.basename(file) === 'package.json') {
const data = require(file);
for (const filename of options.files) {
const file = _path.default.resolve(options.cwd, filename);
delete require.cache[file];
exists = Object.prototype.hasOwnProperty.call(data, options.packageKey);
let exists = process.env.NODE_ENV !== 'test' && this.existsCache.has(file) ? this.existsCache.get(file) : await pathExists(file);
if (exists) {
_this.packageJsonCache.set(file, data[options.packageKey]);
}
} else {
_this.packageJsonCache.delete(file);
}
if (exists && options.packageKey && _path.default.basename(file) === 'package.json') {
const data = require(file);
_this.existsCache.set(file, exists);
delete require.cache[file];
exists = Object.prototype.hasOwnProperty.call(data, options.packageKey);
if (exists) {
return file;
this.packageJsonCache.set(file, data[options.packageKey]);
}
} else {
this.packageJsonCache.delete(file);
}
return _this.recusivelyResolve(Object.assign({}, options, {
cwd: _path.default.dirname(options.cwd)
}));
})();
this.existsCache.set(file, exists);
if (exists) {
return file;
}
}
return this.recusivelyResolve(Object.assign({}, options, {
cwd: _path.default.dirname(options.cwd)
}));
}

@@ -136,33 +140,29 @@

resolve(...args) {
var _this2 = this;
async resolve(...args) {
const options = Object.assign({}, this.options);
return _asyncToGenerator(function* () {
const options = Object.assign({}, _this2.options);
if (Object.prototype.toString.call(args[0]) === '[object Object]') {
Object.assign(options, args[0]);
} else {
if (args[0]) {
options.files = args[0];
}
if (Object.prototype.toString.call(args[0]) === '[object Object]') {
Object.assign(options, args[0]);
} else {
if (args[0]) {
options.files = args[0];
}
if (args[1]) {
options.cwd = args[1];
}
if (args[1]) {
options.cwd = args[1];
}
if (args[2]) {
options.stopDir = args[2];
}
if (args[2]) {
options.stopDir = args[2];
}
}
options.cwd = _path.default.resolve(options.cwd);
options.stopDir = options.stopDir ? _path.default.resolve(options.stopDir) : _path.default.parse(options.cwd).root;
options.cwd = _path.default.resolve(options.cwd);
options.stopDir = options.stopDir ? _path.default.resolve(options.stopDir) : _path.default.parse(options.cwd).root;
if (!options.files || options.files.length === 0) {
throw new Error('files must be an non-empty array!');
}
if (!options.files || options.files.length === 0) {
throw new Error('files must be an non-empty array!');
}
return _this2.recusivelyResolve(options);
})();
return this.recusivelyResolve(options);
}

@@ -199,51 +199,46 @@

load(...args) {
var _this3 = this;
async load(...args) {
const filepath = await this.resolve(...args);
return _asyncToGenerator(function* () {
const filepath = yield _this3.resolve(...args);
if (filepath) {
const loader = this.findLoader(filepath);
if (filepath) {
const loader = _this3.findLoader(filepath);
if (loader) {
return {
path: filepath,
data: await loader.load(filepath)
};
}
if (loader) {
return {
path: filepath,
data: yield loader.load(filepath)
};
}
const extname = _path.default.extname(filepath).slice(1);
const extname = _path.default.extname(filepath).slice(1);
if (extname === 'js') {
return {
path: filepath,
data: require(filepath)
};
}
if (extname === 'js') {
if (extname === 'json') {
if (this.packageJsonCache.has(filepath)) {
return {
path: filepath,
data: require(filepath)
data: this.packageJsonCache.get(filepath)
};
}
if (extname === 'json') {
if (_this3.packageJsonCache.has(filepath)) {
return {
path: filepath,
data: _this3.packageJsonCache.get(filepath)
};
}
const data = _this3.options.parseJSON((yield readFile(filepath)));
return {
path: filepath,
data
};
}
const data = this.options.parseJSON((await readFile(filepath)));
return {
path: filepath,
data: yield readFile(filepath)
data
};
}
return {};
})();
return {
path: filepath,
data: await readFile(filepath)
};
}
return {};
}

@@ -250,0 +245,0 @@

{
"name": "joycon",
"version": "2.1.2",
"version": "2.2.0",
"description": "Load config with ease.",

@@ -27,5 +27,5 @@ "repository": {

"devDependencies": {
"@babel/cli": "^7.0.0-beta.44",
"@babel/core": "^7.0.0-beta.44",
"@babel/preset-env": "^7.0.0-beta.44",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@types/json5": "^0.0.29",

@@ -32,0 +32,0 @@ "@types/node": "^9.6.5",

@@ -103,2 +103,3 @@

interface Loader {
name?: string
test: RegExp

@@ -112,2 +113,6 @@ load(filepath: string)?: Promise<any>

### removeLoader(name)
Remove loaders by loader name.
### clearCache()

@@ -114,0 +119,0 @@

@@ -22,2 +22,4 @@ export interface Options {

export interface AsyncLoader {
/** Optional loader name */
name?: string
test: RegExp

@@ -28,2 +30,4 @@ load(filepath: string): Promise<any>

export interface SyncLoader {
/** Optional loader name */
name?: string
test: RegExp

@@ -34,2 +38,4 @@ loadSync(filepath: string): any

export interface MultiLoader {
/** Optional loader name */
name?: string
test: RegExp

@@ -50,2 +56,3 @@ load(filepath: string): Promise<any>

addLoader(loader: AsyncLoader | SyncLoader | MultiLoader): this
removeLoader(name: string): this
}

@@ -52,0 +59,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc