fepper-utils
Advanced tools
Comparing version 1.0.2 to 1.0.3-rc.0
81
index.js
@@ -67,2 +67,8 @@ 'use strict'; | ||
if (!exports.deepGet(conf, 'ui.paths')) { | ||
exports.error('patternlab-config.json is missing paths, a critical value! Exiting!'); | ||
return; | ||
} | ||
conf.ui.paths.core = `${appDir}/ui/core`; | ||
@@ -87,3 +93,2 @@ | ||
try { | ||
// Require so the config gets cached. Will require again later to instantiate Pattern Lab. | ||
const defaultsStr = fs.readFileSync(`${appDir}/excludes/patternlab-config.json`, enc); | ||
@@ -135,8 +140,8 @@ defaults.ui = JSON5.parse(defaultsStr); | ||
try { | ||
const yml = fs.readFileSync(`${global.appDir}/excludes/pref.yml`, enc); | ||
defaults = yaml.safeLoad(yml); | ||
const yml = fs.readFileSync(`${global.rootDir}/pref.yml`, enc); | ||
pref = global.pref = yaml.safeLoad(yml); | ||
} | ||
catch (err) { | ||
exports.error(err); | ||
exports.error('Missing or malformed excludes/pref.yml! Exiting!'); | ||
exports.error('Missing or malformed pref.yml! Exiting!'); | ||
@@ -147,8 +152,8 @@ return; | ||
try { | ||
const yml = fs.readFileSync(`${global.rootDir}/pref.yml`, enc); | ||
pref = yaml.safeLoad(yml); | ||
const yml = fs.readFileSync(`${global.appDir}/excludes/pref.yml`, enc); | ||
defaults = yaml.safeLoad(yml); | ||
} | ||
catch (err) { | ||
exports.error(err); | ||
exports.error('Missing or malformed pref.yml! Exiting!'); | ||
exports.error('Missing or malformed excludes/pref.yml! Exiting!'); | ||
@@ -160,2 +165,3 @@ return; | ||
// Write to global object. | ||
global.pref = pref; | ||
@@ -187,2 +193,46 @@ | ||
/** | ||
* Get data from a nested property within an object. | ||
* | ||
* @param {object} obj - The object from which to get the data. | ||
* @param {string|array} path - Dot-notation string to the nested property, or array of keys if dot-notation won't work. | ||
* @return {*|null} The retrieved data or null on failure. | ||
*/ | ||
exports.deepGet = (obj, path) => { | ||
if (!obj instanceof Object) { | ||
return null; | ||
} | ||
let pathElements; | ||
if (typeof path === 'string') { | ||
pathElements = path.split('.'); | ||
} | ||
else if (Array.isArray(path)) { | ||
pathElements = path; | ||
} | ||
else { | ||
return null; | ||
} | ||
const firstElement = pathElements.shift(); | ||
if (pathElements.length > 1) { | ||
if (obj[firstElement]) { | ||
return exports.deepGet(obj[firstElement], pathElements); | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
else { | ||
if (obj[firstElement]) { | ||
return obj[firstElement]; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
} | ||
/** | ||
* Recursively merge properties of two objects. | ||
@@ -465,4 +515,17 @@ * | ||
if (arguments.length) { | ||
arguments[0] = '\x1b[31m' + arguments[0] + '\x1b[0m'; | ||
const error = arguments[0]; | ||
if ( | ||
global.conf && | ||
exports.deepGet(global.conf, 'ui.debug') === true && | ||
error instanceof Error && | ||
error.stack | ||
) { | ||
arguments[0] = '\x1b[31m' + error.stack + '\x1b[0m'; | ||
} | ||
else { | ||
arguments[0] = '\x1b[31m' + error + '\x1b[0m'; | ||
} | ||
} | ||
exports.console.error.apply(null, arguments); | ||
@@ -498,2 +561,3 @@ }; | ||
} | ||
exports.console.info.apply(null, arguments); | ||
@@ -521,2 +585,3 @@ }; | ||
} | ||
exports.console.warn.apply(null, arguments); | ||
@@ -523,0 +588,0 @@ }; |
{ | ||
"name": "fepper-utils", | ||
"version": "1.0.2", | ||
"version": "1.0.3-rc.0", | ||
"description": "Fepper utilities", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,2 +18,5 @@ # Fepper Utilities | ||
<dl> | ||
<dt><a href="#deepGet">deepGet(obj, path)</a> ⇒ <code>*</code> | <code>null</code></dt> | ||
<dd><p>Get data from a nested property within an object.</p> | ||
</dd> | ||
<dt><a href="#extendButNotOverride">extendButNotOverride(obj1, obj2)</a> ⇒ <code>object</code></dt> | ||
@@ -79,2 +82,15 @@ <dd><p>Recursively merge properties of two objects.</p> | ||
<a name="deepGet"></a> | ||
## deepGet(obj, path) ⇒ <code>\*</code> \| <code>null</code> | ||
Get data from a nested property within an object. | ||
**Kind**: global function | ||
**Returns**: <code>\*</code> \| <code>null</code> - The retrieved data or null on failure. | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| obj | <code>object</code> | The object from which to get the data. | | ||
| path | <code>string</code> \| <code>array</code> | Dot-notation string to the nested property, or array of keys if dot-notation won't work. | | ||
<a name="extendButNotOverride"></a> | ||
@@ -81,0 +97,0 @@ |
16
utils.md
## Functions | ||
<dl> | ||
<dt><a href="#deepGet">deepGet(obj, path)</a> ⇒ <code>*</code> | <code>null</code></dt> | ||
<dd><p>Get data from a nested property within an object.</p> | ||
</dd> | ||
<dt><a href="#extendButNotOverride">extendButNotOverride(obj1, obj2)</a> ⇒ <code>object</code></dt> | ||
@@ -64,2 +67,15 @@ <dd><p>Recursively merge properties of two objects.</p> | ||
<a name="deepGet"></a> | ||
## deepGet(obj, path) ⇒ <code>\*</code> \| <code>null</code> | ||
Get data from a nested property within an object. | ||
**Kind**: global function | ||
**Returns**: <code>\*</code> \| <code>null</code> - The retrieved data or null on failure. | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| obj | <code>object</code> | The object from which to get the data. | | ||
| path | <code>string</code> \| <code>array</code> | Dot-notation string to the nested property, or array of keys if dot-notation won't work. | | ||
<a name="extendButNotOverride"></a> | ||
@@ -66,0 +82,0 @@ |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
43025
607
268
1
1