vigour-util
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -6,7 +6,7 @@ 'use strict' | ||
* @id flatten | ||
* @function Take a nested Javascript object and flatten it | ||
* @function flatten | ||
* Transforms a deep object into an object of single depth where keys are a path and values are leafs of the original object. | ||
* @param {object} subject - Object that needs to be flattened | ||
* @param {string} [seperator] - Optional seperator sign | ||
* @return {object} - Object with delimited keys | ||
* @param {string} [seperator] - Optional seperator sign, defaults to `'.'` | ||
* @return {object} flat - Object with delimited keys | ||
*/ | ||
@@ -13,0 +13,0 @@ function flatten (subject, separator) { |
@@ -7,3 +7,3 @@ 'use strict' | ||
* @function isHash | ||
* Checks is a string looks like a hash generated by the [`hash`](#hash) utility | ||
* Checks if a string looks like a hash generated by the [`hash`](#hash) utility | ||
* @param {string} val - the string to check | ||
@@ -10,0 +10,0 @@ * @returns {boolean} looksLikeHash - `true` if `val` looks like a hash, `false` otherwise |
{ | ||
"name": "vigour-util", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"author": "Vigour.io <dev@vigour.io>", | ||
@@ -22,2 +22,3 @@ "scripts": { | ||
"is-stream": "^1.0.1", | ||
"lodash.isarray": "^4.0.0", | ||
"lodash.isfinite": "^3.3.0", | ||
@@ -24,0 +25,0 @@ "lodash.isfunction": "^3.0.8", |
113
README.md
@@ -6,2 +6,3 @@ <!-- VDOC.badges travis; standard; npm --> | ||
[![npm version](https://badge.fury.io/js/vigour-util.svg)](https://badge.fury.io/js/vigour-util) | ||
<!-- VDOC END --> | ||
@@ -27,4 +28,5 @@ # vigour-util | ||
Checks whether provided parameter looks like a valid e-mail address | ||
- **param** {*string*} val - the string to check | ||
- **returns** {*boolean*} valid - `true` if `val` is a valid e-mail address, `false` otherwise | ||
- **val** (*string*) - the string to check | ||
- **returns** (*boolean*) valid - `true` if `val` is a valid e-mail address, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -42,5 +44,6 @@ | ||
Checks is a string looks like a hash generated by the [`hash`](#hash) utility | ||
- **param** {*string*} val - the string to check | ||
- **returns** {*boolean*} looksLikeHash - `true` if `val` looks like a hash, `false` otherwise | ||
Checks if a string looks like a hash generated by the [`hash`](#hash) utility | ||
- **val** (*string*) - the string to check | ||
- **returns** (*boolean*) looksLikeHash - `true` if `val` looks like a hash, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -57,2 +60,3 @@ | ||
- **returns** runningInNode - `true` if in node context, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -70,4 +74,5 @@ | ||
This just calls `lodash.isfinite` internally. See [those docs](https://lodash.com/docs#isFinite) | ||
- **param** {*any*} value - The value to check | ||
- **returns** {*boolean*} finiteNumber - Returns `true` if *value* is a finite number, `false` otherwise | ||
- **value** (*any*) - The value to check | ||
- **returns** (*boolean*) finiteNumber - Returns `true` if *value* is a finite number, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -86,4 +91,5 @@ | ||
Checks whether provided parameter looks like a number | ||
- **param** {*any*} val - the value to check | ||
- **returns** {*boolean*} looksLikeNumber - `true` if `val` looks like a number, `false` otherwise | ||
- **val** (*any*) - the value to check | ||
- **returns** (*boolean*) looksLikeNumber - `true` if `val` looks like a number, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -102,4 +108,5 @@ | ||
Checks whether provided argument is a stream | ||
- **param** {*object*} val - the object to check | ||
- **returns** {*boolean*} stream - `true` if `val` is a stream, `false` otherwise | ||
- **val** (*object*) - the object to check | ||
- **returns** (*boolean*) stream - `true` if `val` is a stream, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -119,4 +126,5 @@ | ||
Checks whether provided argument is a readable stream | ||
- **param** {*object*} val - the object to check | ||
- **returns** {*boolean*} readable - `true` if `val` is a readable stream, `false` otherwise | ||
- **val** (*object*) - the object to check | ||
- **returns** (*boolean*) readable - `true` if `val` is a readable stream, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -136,4 +144,5 @@ | ||
Checks whether provided argument is a writable stream | ||
- **param** {*object*} val - the object to check | ||
- **returns** {*boolean*} writable - `true` if `val` is a writable stream, `false` otherwise | ||
- **val** (*object*) - the object to check | ||
- **returns** (*boolean*) writable - `true` if `val` is a writable stream, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -153,3 +162,4 @@ | ||
Checks if we're running in a touch-enabled context | ||
- **returns** {*boolean*} touch - `true` if we're in a touch-enabled context, `false` otherwise | ||
- **returns** (*boolean*) touch - `true` if we're in a touch-enabled context, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -167,4 +177,5 @@ | ||
Checks if a string is a valid url | ||
- **param** {*string*} val - the string to check | ||
- **returns** {*boolean*} valid - `true` if *val* is a valid url, `false` otherwise | ||
- **val** (*string*) - the string to check | ||
- **returns** (*boolean*) valid - `true` if *val* is a valid url, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -183,4 +194,5 @@ | ||
Checks whether an object is a plain object (excludes streams, buffers, base and null) (*Compatible with `vigour-base`*) | ||
- **param** {*object*} obj - the object to check | ||
- **returns** {*boolean*} plain - `true` if *obj* is a plain object, `false` otherwise | ||
- **obj** (*object*) - the object to check | ||
- **returns** (*boolean*) plain - `true` if *obj* is a plain object, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -199,4 +211,5 @@ | ||
Checks if a property has been removed (*Specific to `vigour-base`*) | ||
- **param** {*Base*} base - the property to check | ||
- **returns** {*boolean*} removed - `true` if *base* property has been removed, `false` otherwise | ||
- **base** (*Base*) - the property to check | ||
- **returns** (*boolean*) removed - `true` if *base* property has been removed, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -217,4 +230,5 @@ | ||
Checks if a `Base` object is empty (*Specific to `vigour-base`*) | ||
- **param** {*object*} obj - the object to check for emptiness | ||
- **returns** {*boolean*} emptyBase - `true` if `obj` is considered empty, `false` otherwise | ||
- **obj** (*object*) - the object to check for emptiness | ||
- **returns** (*boolean*) emptyBase - `true` if `obj` is considered empty, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -235,5 +249,6 @@ | ||
Checks whether a key is part of an array, allowing for prefixed keys | ||
- **param** {*array*} path - the array to look in | ||
- **param** {*string*} key - the key to check for | ||
- **returns** {*boolean*} found - `true` if *key* is found in *array*, `false` otherwise | ||
- **path** (*array*) - the array to look in | ||
- **key** (*string*) - the key to check for | ||
- **returns** (*boolean*) found - `true` if *key* is found in *array*, `false` otherwise | ||
<!-- VDOC END --> | ||
@@ -254,2 +269,3 @@ | ||
A process-specific unique ID, generated on `require` | ||
<!-- VDOC END --> | ||
@@ -267,3 +283,4 @@ | ||
Generates a unique ID | ||
- **returns** {*string*} id - A unique ID | ||
- **returns** (*string*) id - A unique ID | ||
<!-- VDOC END --> | ||
@@ -281,3 +298,4 @@ | ||
Defines new (or modifies existing) properties (using [`Object.defineProperty`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)) on an object passed to `define` as `this`, setting `configurable: true` by default | ||
- **param** {*object*} props - Properties to set | ||
- **props** (*object*) - Properties to set | ||
<!-- VDOC END --> | ||
@@ -303,3 +321,4 @@ | ||
Like [`Object.getOwnPropertyDescriptor`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor), but goes along the prototype chain and gets the descriptors for all properties. | ||
- **param** {*object*} props - the properties to get the descriptors for | ||
- **props** (*object*) - the properties to get the descriptors for | ||
<!-- VDOC END --> | ||
@@ -330,8 +349,9 @@ | ||
<!-- DON'T EDIT THIS SECTION (including comments), INSTEAD RE-RUN `vdoc` TO UPDATE --> | ||
#### var *object* = Take a nested Javascript object and flatten it(subject) | ||
#### var flat = flatten(subject) | ||
Transforms a deep object into an object of single depth where keys are a path and values are leafs of the original object. | ||
- **param** {*object*} subject - Object that needs to be flattened | ||
- **param** {*string*} [seperator] - Optional seperator sign | ||
- **return** {*object*} - Object with delimited keys | ||
- **subject** (*object*) - Object that needs to be flattened | ||
- **[seperator]** (*string*) - Optional seperator sign, defaults to `'.'` | ||
- **return** (*object*) flat - Object with delimited keys | ||
<!-- VDOC END --> | ||
@@ -350,5 +370,6 @@ | ||
Hashing utility optimized for speed, not collision avoidance. Produces alpha-numeric hashes between 5 and 7 characters long inclusively. | ||
- **param** {*string*} key - the string to hash | ||
- **param** {*number*} seed - a seed for hashing | ||
- **returns** {*string*} hashOfKey - The created hash | ||
- **key** (*string*) - the string to hash | ||
- **seed** (*number*) - a seed for hashing | ||
- **returns** (*string*) hashOfKey - The created hash | ||
<!-- VDOC END --> | ||
@@ -372,2 +393,3 @@ | ||
Like Babel's regenerator, but much more compact. Brought to you by Facebook, but bundled in `vigour-util` for ease-of-use. See [the docs](https://github.com/facebook/regenerator) | ||
<!-- VDOC END --> | ||
@@ -383,5 +405,6 @@ | ||
Opposite of [`flatten`](#flatten). Unflattens an object with delimited keys | ||
- **param** {*object*} subject - Object that needs to be unflattened | ||
- **param** {*string*} [seperator] - Optional seperator sign | ||
- **return** {*object*} obj - Nested Javascript object | ||
- **subject** (*object*) - Object that needs to be unflattened | ||
- **[seperator]** (*string*) - Optional seperator sign | ||
- **return** (*object*) obj - Nested Javascript object | ||
<!-- VDOC END --> | ||
@@ -410,4 +433,5 @@ | ||
Get's the referenced object (*Specific to `vigour-base`*) | ||
- **param** {*object*} obj - the reference we want to follow | ||
- **returns** {*object*} ref - The referenced object or `undefined` | ||
- **obj** (*object*) - the reference we want to follow | ||
- **returns** (*object*) ref - The referenced object or `undefined` | ||
<!-- VDOC END --> | ||
@@ -431,7 +455,8 @@ | ||
Outside of node (browserify, webpack, etc.), this function does nothing. | ||
- **param** {*object*} options - Options to further define the behaviour of `require`: | ||
- **options** (*object*) - Options to further define the behaviour of `require`: | ||
- + {*boolean*} **options.package** : set to `true` to convert `require('package.json')` to `JSON.parse(require(process.cwd() + '/package.json'))` | ||
- + {*boolean|string|function*} **options.exclude** : additional paths to exclude. If a function is provided, `require` will exclude paths for which the function returns `true` | ||
- + {*string|regexp|function|array*} **options.exclude** : paths containing the specified string, or matching the specified regexp, or for which specified function returns `true`, will be excluded. If an array is provided, each element is treated exactly the same as `options.exclude` and only paths which aren't excluded by any item will be `require`d. | ||
<!-- VDOC END --> | ||
@@ -438,0 +463,0 @@ |
@@ -8,2 +8,3 @@ 'use strict' | ||
var isNode = require('./is/node') | ||
var _isArray = require('lodash.isArray') | ||
var _isFunction = require('lodash.isfunction') | ||
@@ -28,3 +29,3 @@ var _isRegExp = require('lodash.isRegExp') | ||
* - + {*boolean*} **options.package** : set to `true` to convert `require('package.json')` to `JSON.parse(require(process.cwd() + '/package.json'))` | ||
* - + {*boolean|string|function*} **options.exclude** : additional paths to exclude. If a function is provided, `require` will exclude paths for which the function returns `true` | ||
* - + {*string|regexp|function|array*} **options.exclude** : paths containing the specified string, or matching the specified regexp, or for which specified function returns `true`, will be excluded. If an array is provided, each element is treated exactly the same as `options.exclude` and only paths which aren't excluded by any item will be `require`d. | ||
*/ | ||
@@ -44,24 +45,7 @@ function enhanceRequire (_options) { | ||
} | ||
if (options.exclude) { | ||
if (_isFunction(options.exclude) && options.exclude(path)) { | ||
return {} | ||
} else if (_isRegExp(options.exclude) && options.exclude.test(path)) { | ||
return {} | ||
} else if (_isString(options.exclude) && path.indexOf(options.exclude) !== -1) { | ||
return {} | ||
} | ||
} | ||
if (/\.less/.test(path)) { | ||
if (exclude(options.exclude, path, next)) { | ||
return {} | ||
} else { | ||
return next(path) | ||
} | ||
if (/\.css/.test(path)) { | ||
return {} | ||
} | ||
if (/\.scss/.test(path)) { | ||
return {} | ||
} | ||
if (/\.sass/.test(path)) { | ||
return {} | ||
} | ||
return next(path) | ||
} | ||
@@ -71,2 +55,39 @@ require.next = Module.prototype.require | ||
} | ||
function exclude (options_exclude, path) { | ||
if (options_exclude) { | ||
if (_isArray(options_exclude)) { | ||
let excludeIt = false | ||
let len = options_exclude.length | ||
for (let i = 0; i < len && !excludeIt; i += 1) { | ||
if (exclude(options_exclude[i], path)) { | ||
excludeIt = true | ||
} | ||
} | ||
if (excludeIt) { | ||
return true | ||
} | ||
} else if (_isFunction(options_exclude) && options_exclude(path)) { | ||
return true | ||
} else if (_isRegExp(options_exclude) && options_exclude.test(path)) { | ||
return true | ||
} else if (_isString(options_exclude) && path.indexOf(options_exclude) !== -1) { | ||
return true | ||
} | ||
} | ||
if (/\.less/.test(path)) { | ||
return true | ||
} | ||
if (/\.css/.test(path)) { | ||
return true | ||
} | ||
if (/\.scss/.test(path)) { | ||
return true | ||
} | ||
if (/\.sass/.test(path)) { | ||
return true | ||
} | ||
return false | ||
} | ||
/** | ||
@@ -73,0 +94,0 @@ * @id require.restore |
@@ -1,1 +0,1 @@ | ||
console.log('If you see this message in node, something is wrong') | ||
console.log('If you see this message in node, something is wrong, scratch') |
@@ -7,3 +7,3 @@ 'use strict' | ||
test('require', function (t) { | ||
t.plan(6) | ||
t.plan(7) | ||
var enhanceRequire = require('../require') | ||
@@ -29,2 +29,3 @@ var count = 0 | ||
enhanceRequire({ | ||
package: true, | ||
exclude: '/scratch/' | ||
@@ -72,2 +73,22 @@ }) | ||
t.equals(count, isNode ? 1 : 0, "`require('vigour-util/require').restore()` should restore the original `require`") | ||
enhanceRequire({ | ||
exclude: [ | ||
'scratch', | ||
/nooo/, | ||
function (item) { | ||
return item.indexOf('naaay') !== -1 | ||
} | ||
] | ||
}) | ||
count = 0 | ||
try { | ||
require('./_files/scratch/this-should-be-ignored') | ||
require('./_files/nooo/this-should-be-ignored') | ||
require('./_files/naaay/this-should-be-ignored') | ||
} catch (e) { | ||
count += 1 | ||
} | ||
t.equals(count, 0, "`require('vigour-util/require').restore()` should accept an array of ignores") | ||
enhanceRequire.restore() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75922
60
1803
451
8
+ Addedlodash.isarray@^4.0.0
+ Addedlodash.isarray@4.0.0(transitive)