Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vigour-util

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vigour-util - npm Package Compare versions

Comparing version 2.0.5 to 2.0.6

test/include.js

8

include.js
'use strict'
/**
* @id include
* @function include
* Distinctly adds one or multiple items (in an object or array) to a target array. Doesn't duplicate items.
* @param {Array} target - target array
* @param thing - the thing to be included in the array. If object or array, it will go through it and add all values to the target array.
* @returns {Array} included - Array representing the included items (duplicates removed)
*/
var include = module.exports = function include (target, thing) {

@@ -4,0 +12,0 @@ return typeof thing === 'object'

17

is/url.js
'use strict'
var url = /^(((ws(s)?)|(http(s)?))\:\/\/)?[a-zA-Z0-9_-]+(\.|\:)([^\/\/])[a-zA-Z/0-9$-/:-?{#-~!"^_`\[\]]+$/
var protocol = '(((ws(s)?)|(http(s)?))\\:\\/\\/)'
var domain = '[a-zA-Z0-9_-]+'
var other = '([a-zA-Z/0-9$-/:-?{#-~!"^_`\\[\\]]+)?'
var ext = '(\\.' + other + ')'
var port = '(\\:[0-9]+)?'
var ip = '([a-zA-Z0-9]{4}:)+[a-zA-Z0-9]'
/**

@@ -8,6 +13,12 @@ * @id isUrl

* @param {string} val - the string to check
* @param {object} [options] - defaults to `{}`
* - **options.requireProtocol** {boolean} - set to true if you only want URLs with a protocol to be considered valid. Defaults to `false`
* @returns {boolean} valid - `true` if *val* is a valid url, `false` otherwise
*/
module.exports = function (val) {
return typeof val === 'string' && url.test(val) || val === 'localhost'
module.exports = function (val, options) {
if (!options) {
options = {}
}
var re = new RegExp('^' + protocol + (!options.requireProtocol ? '?' : '') + '(' + domain + ext + '|localhost|' + ip + ')' + port + other + '$')
return typeof val === 'string' && re.test(val)
}

9

package.json
{
"name": "vigour-util",
"version": "2.0.5",
"version": "2.0.6",
"author": "Vigour.io <dev@vigour.io>",
"scripts": {
"test": "node test | tap-difflet && vtest test | tap-difflet"
"test": "NODE_ENV=test node test | tap-difflet && vtest test | tap-difflet",
"cover": "istanbul cover --report none --print detail test/index.js",
"view-cover": "istanbul report html && open ./coverage/index.html",
"travis": "npm run cover -s && istanbul report lcov && ((cat coverage/lcov.info | coveralls) || exit 0)"
},

@@ -46,2 +49,4 @@ "repository": {

"browserify": "^13.0.0",
"coveralls": "^2.11.9",
"istanbul": "^0.4.3",
"nightmare": "^2.2.0",

@@ -48,0 +53,0 @@ "node-lessify": "^0.1.1",

@@ -1,2 +0,2 @@

<!-- VDOC.badges travis; standard; npm -->
<!-- VDOC.badges travis; standard; npm; coveralls -->
<!-- DON'T EDIT THIS SECTION (including comments), INSTEAD RE-RUN `vdoc` TO UPDATE -->

@@ -6,2 +6,3 @@ [![Build Status](https://travis-ci.org/vigour-io/util.svg?branch=master)](https://travis-ci.org/vigour-io/util)

[![npm version](https://badge.fury.io/js/vigour-util.svg)](https://badge.fury.io/js/vigour-util)
[![Coverage Status](https://coveralls.io/repos/github/vigour-io/util/badge.svg?branch=master)](https://coveralls.io/github/vigour-io/util?branch=master)

@@ -165,6 +166,9 @@ <!-- VDOC END -->

<!-- DON'T EDIT THIS SECTION (including comments), INSTEAD RE-RUN `vdoc` TO UPDATE -->
#### var valid = isUrl(val)
#### var valid = isUrl(val, [options])
Checks if a string is a valid url
- **val** (*string*) - the string to check
- **[options]** (*object*) - defaults to `{}`
- **options.requireProtocol** {boolean} - set to true if you only want URLs with a protocol to be considered valid. Defaults to `false`
- **returns** (*boolean*) valid - `true` if *val* is a valid url, `false` otherwise

@@ -332,3 +336,3 @@

<!-- DON'T EDIT THIS SECTION (including comments), INSTEAD RE-RUN `vdoc` TO UPDATE -->
#### var flat = flatten(subject)
#### var flat = flatten(subject, [seperator])

@@ -364,5 +368,21 @@ Transforms a deep object into an object of single depth where keys are a path and values are leafs of the original object.

### include
Docs coming soon
<!-- VDOC.jsdoc include -->
<!-- DON'T EDIT THIS SECTION (including comments), INSTEAD RE-RUN `vdoc` TO UPDATE -->
#### var included = include(target, thing)
Distinctly adds one or multiple items (in an object or array) to a target array. Doesn't duplicate items.
- **target** (*Array*) - target array
- **thing** - the thing to be included in the array. If object or array, it will go through it and add all values to the target array.
- **returns** (*Array*) included - Array representing the included items (duplicates removed)
<!-- VDOC END -->
```javasript
var include = require('vigour-util/include')
var target = [1]
include(target, [2, 1, 3]) // returns [2, 3]
console.log(target) // logs [1, 2, 3]
```
### merge

@@ -384,3 +404,3 @@ ***Obsolete***: This function has been removed in version 2. Use [`lodash.merge`](https://www.npmjs.com/package/lodash.merge) instead.

<!-- DON'T EDIT THIS SECTION (including comments), INSTEAD RE-RUN `vdoc` TO UPDATE -->
#### var obj = unflatten(subject)
#### var obj = unflatten(subject, [seperator])

@@ -431,3 +451,3 @@ Opposite of [`flatten`](#flatten). Unflattens an object with delimited keys

<!-- DON'T EDIT THIS SECTION (including comments), INSTEAD RE-RUN `vdoc` TO UPDATE -->
#### enhanceRequire(options)
#### enhanceRequire([options])

@@ -437,3 +457,3 @@ In node, modifies the behaviour of `require` so that it ignores paths containing `.css`, `.less`, `.scss`, `.sass`, and any other paths indicated via the `exclude` option.

Outside of node (browserify, webpack, etc.), this function does nothing.
- **options** (*object*) - Options to further define the behaviour of `require`:
- **[options]** (*object*) - Options to further define the behaviour of `require`:

@@ -440,0 +460,0 @@ - + {*boolean*} **options.package** : set to `true` to convert `require('package.json')` to `JSON.parse(require(process.cwd() + '/package.json'))`

@@ -8,13 +8,13 @@ 'use strict'

var isNode = require('./is/node')
var _isArray = require('lodash.isArray')
var _isArray = require('lodash.isarray')
var _isFunction = require('lodash.isfunction')
var _isRegExp = require('lodash.isRegExp')
var _isString = require('lodash.isString')
var _isRegExp = require('lodash.isregexp')
var _isString = require('lodash.isstring')
var originalRequire
if (isNode) { // else let browserify (or similar) do it
if (isNode) {
originalRequire = Module.prototype.require
module.exports = enhanceRequire
} else {
} else { // let browserify (or similar) do it
module.exports = enhanceRequireMock

@@ -28,3 +28,3 @@ }

* Outside of node (browserify, webpack, etc.), this function does nothing.
* @param {object} options - Options to further define the behaviour of `require`:
* @param {object} [options] - 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'))`

@@ -31,0 +31,0 @@ * - + {*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.

@@ -13,1 +13,2 @@ 'use strict'

require('./require')
require('./include.js')

@@ -13,7 +13,13 @@ 'use strict'

['http://domain.ext/path?query=string#withHash', true],
['http://domain.ext:8000', true],
['localhost', true],
['localhost/path', true],
['localhost:8080', true],
['localhost:8080/path', true],
['192.11.222.444', true],
['192.11.222.444/path', true],
['2001:0db8:0000:0042:0000:8a2e:0370:7334', true],
['2001:0db8:0000:0042:0000:8a2e:0370:7334/path', true],
['ws://localhost:8080', true],
['ws://localhost:8080/path', true],
['wss://etc.com', true]

@@ -23,6 +29,46 @@ ]

test('isURL', function (t) {
t.plan(testCases.length)
testCases.forEach(function (item) {
t.equals(isURL(item[0]), item[1], 'isURL(' + item[0] + ') === ' + item[1])
})
var nb = testCases.length
t.plan(nb)
for (let i = 0; i < nb; i += 1) {
t.equals(isURL(testCases[i][0]), testCases[i][1], 'isURL(\'' + testCases[i][0] + '\') === ' + testCases[i][1])
}
})
var protocolCases = [
// ['url', expectedResult]
['string', false],
['domain.ext', false],
['http://domain.ext/path?query=string', true],
['https://domain.ext/path?query=string%20with%20spaces', true],
['https://domain.ext/path#withHash', true],
['http://domain.ext/path?query=string#withHash', true],
['http://domain.ext:8000', true],
['domain.ext:8000', false],
['localhost', false],
['localhost/path', false],
['localhost:8080', false],
['localhost:8080/path', false],
['192.11.222.444', false],
['192.11.222.444/path', false],
['2001:0db8:0000:0042:0000:8a2e:0370:7334', false],
['2001:0db8:0000:0042:0000:8a2e:0370:7334/path', false],
['ws://localhost:8080', true],
['ws://localhost:8080/path', true],
['wss://etc.com', true],
['http://localhost', true],
['http://localhost/path', true],
['http://localhost:8080', true],
['http://localhost:8080/path', true],
['http://192.11.222.444', true],
['http://192.11.222.444/path', true],
['http://2001:0db8:0000:0042:0000:8a2e:0370:7334', true],
['http://2001:0db8:0000:0042:0000:8a2e:0370:7334/path', true]
]
test('isUrl (requireProtocol)', function (t) {
var nb = protocolCases.length
t.plan(nb)
for (let i = 0; i < nb; i += 1) {
t.equals(isURL(protocolCases[i][0], { requireProtocol: true }), protocolCases[i][1], 'isURL(\'' + protocolCases[i][0] + '\', { requireProtocol: true }) === ' + protocolCases[i][1])
}
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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