Grab bag of utilities for vandelay transform functions.
npm install vandelay-util --save
Utility functions will return undefined when given null or invalid values when appropriate.
For example:
const row = {
name: 'pear'
}
util.capitalize(row.notes) // undefined
util.convert(row.speed).from('m/h').to('km/h') // undefinedStringifies all provided values and turns them into a deterministic GUID. Null values are ignored.
util.guid('Michael Scott', 'Birthday', null, 1993) // f8e61be1-0b1c-4e4f-81b6-050ae9b8a049Stringifies all provided values and turns them into a lowercase slug. Null values are ignored.
util.slug('Michael Scott', 'Birthday', null, 1993) // michael-scott-birthday-1993Trims, lowercases, and removes redundant whitespace from the given value.
util.normalize('\t HEY \n THANKS') // hey thanksCapitalizes the first word in the given value.
Capitalizes every word in the given value.
Normalizes any phone number in the world. Country is any three letter country code, defaulting to 'USA'. If the number includes a country code, you do not need to provide a country argument.
util.phone(' 123 ') // undefined
util.phone(123) // undefined
// USA numbers
util.phone('4805335949') // +14805335949
util.phone('(480) 533-5949') // +14805335949
util.phone('480-533-5949') // +14805335949
util.phone(4805335949) // +14805335949
// Hong Kong numbers
util.phone('6123-6123') // undefined
util.phone('6123-6123', 'HKG') // +85261236123
util.phone('+852 6123-6123') // +85261236123
})Exposes convert-units, with additional handling of null and invalid values. For a full list of convertible units, see this page.
util.convert(null).from('m/h').to('km/h') // undefined
util.convert('1').from('F').to('C') // -17.22222222222222
util.convert(1).from('mi').to('km') // 1.6093439485009937Exposes moment + moment-timezone, with additional handling of null and invalid values. For a full list of time zones, see this page.
util.moment(null) // undefined
util.moment('12/27/1993') // moment object
util.moment.tz('12/27/1993', 'America/New_York') // moment objectWrapper around moment.js moment.tz(date, timezone) that handles null and invalid values. Search timezones here.
util.date('abc', 'America/New_York') // undefined
util.date(null, 'America/Los_Angeles') // undefined
util.date('12/27/1993', 'America/New_York') // 1993-12-27T05:00:00.000ZWrapper around number parsing that handles null and invalid values.
util.number('$100.56') // 100.56
util.number(100.56) // 100.56
util.number('costs $100.56') // 100.56
util.number('it is -100.56') // -100.56Returns true if the coordinate is in the sea. Value can be either [ lon, lat ] or a GeoJSON Point.
util.geo.isSea([ 0, 0 ]) // trueReturns the timezone for a given point. Value returned can be used as the timezone for util.date. Value can be either [ lon, lat ] or a GeoJSON Point.
util.geo.tz([ -118.250587 , 34.031179 ]) // America/Los_Angeles
util.geo.tz({
type: 'Point',
coordinates: [ 121.456424, 31.224417 ]
}) // Asia/ShanghaiConverts any given GeoJSON geometry to a Multi version. Values that are already a Multi geometry will be returned with no modifications.
util.geo.multi({
type: 'Polygon',
coordinates: [
[ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ],
[ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ], [ 100.2, 0.2 ] ]
]
})Converts Well-Known-Text to GeoJSON - supports WKT/WKB/EWKT/EWKB/TWKB.
util.geo.wk2JSON('POINT(1 2)') // { type: 'Point', coordinates: [1, 2] }Exposes turf with no modifications.
Exposes lodash with no modifications.
Exposes validator with no modifications.
Exposes superagent with no modifications.