vigour-util
npm install vigour-util
This is a collection of small utility functions which can be required individually.
get
(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)
is
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')
(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 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()
Checks whether provided parameter is a number
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 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)
Checks whether provided argument is a stream
var stream = require('stream')
var rs = new stream.Readable()
var isStream = require('vigour-util/is/stream')
isStream(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')
path
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')
Others
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'
})