vigour-util
npm install vigour-util
This is a collection of small utility functions which can be required individually.
Contents
Checks whether provided parameter looks like a valid e-mail address
var isEmail = require('vigour-util/is/email')
isEmail('dev@vigour..io')
isEmail('dev@vigour.io')
Checks is a string looks like a hash generated by the hash
utility
var isHash = require('vigour-util/is/hash')
isHash('asd654')
Check whether we're running in node
var isNode = require('vigour-util/is/node')
isNode()
Alias for lodash.isfinite
var isNumber = require('vigour-util/is/number')
isNumber(2)
isNumber('2')
Checks whether provided parameter looks like a number
var isNumberLike = require('vigour-util/is/numberlike')
isNumberLike('2')
isNumberLike('a')
Checks whether provided argument implements the stream interface
var stream = require('stream')
var rs = new stream.Readable()
var isStream = require('vigour-util/is/stream')
isStream(rs)
Checks whether provided argument implements the readable stream interface
var stream = require('stream')
var rs = new stream.Readable()
var isStream = require('vigour-util/is/stream')
isStream.readable(rs)
Checks whether provided argument implements the writable stream interface
var stream = require('stream')
var rs = new stream.Readable()
var isStream = require('vigour-util/is/stream')
isStream.writable(rs)
Checks if we're running in a touch-enabled context
var isTouch = require('vigour-util/is/touch')
isTouch()
Checks if a string is a valid url
var isUrl = require('vigour-util/is/url')
isUrl('http://perdu.com')
isUrl('boom')
Checks whether an object is a plain object. (Compatible with vigour-base
)
var isPlainObj = require('vigour/util/is/plainobj')
isPlainObj({})
isPlainObj(new Base({}))
(Specific to vigour-base
) Checks if a property has been removed
var isRemoved = require('vigour-util/is/removed')
var Base = require('vigour-base')
var base = new Base({ bad: true })
base.bad.remove()
isRemoved(base.bad)
(Specific to vigour-base
) Checks if a Base
object is empty
var isEmpty = require('vigour-util/is/empty')
var Base = require('vigour-base')
isEmpty(new Base({}))
isEmpty(new Base({ awesome: true }))
Checks whether a key is part of an array, allowing for prefixed keys
var pathContains = require('vigour-util/path/contains')
pathContains(['a','awesome:b','c'], 'b')
A process-specific unique ID (or device-specific on browser)
var uuid = require('vigour-util/uuid')
uuid.val
Generates a process-specific unique ID (or device-specific on browser)
var uuid = require('vigour-util/uuid')
uuid.generate()
Defines new or modifies existing properties (using Object.defineProperty
) on an object, setting configurable: true
by default.
var define = require('vigour-util/define')
var subject = {}
var props = [
{ one: true },
{ two: function () {
console.log('do nothing')
}
}
]
define.apply(subject, props)
Like Object.getOwnPropertyDescriptor
, but goes along the prototype chain and get's the descriptors for all properties.
var descriptors = require('vigour-util/descriptors')
descriptors({ a: 'a', b: 'b' })
Transforms a deep object into an object of single depth where keys are a path and values are leafs or the original object.
var flatten = require('vigour-util/flatten')
flatten({ a: { b: 'c', d: 'e' } })
flatten({ a: { b: 'c', d: 'e' } }, '/')
Hashing utility optimized for speed, not collision avoidance. Produces alpha-numeric hashes between 5 and 7 characters long inclusively.
var hash = require('vigour-util')
hash('Any sting in the world!!!')
Deprecated: consider using lodash.merge
var merge = require('vigour-util/merge')
merge({ a: { b: 'b' } }, { a: { c: 'c' } })
Like Babel's regenerator, but much more compact. Brought to you by Facebook, but bundled in vigour-util
for ease-of-use.
Deprecated: consider using lodash.set
Opposite of flatten
var unflatten = require('vigour-util')
unflatten({
'a.b.c': 'd'
})
(Specific to vigour-base
) Get's the referenced object
var Base = require('vigour-base')
var getReference = require('../../get/reference')
var a = new Base({})
var b = new Base(a)
getReference(b)