to-funcs
v0.4.0
Published
A very limited subset of to-* functions I use every day
Downloads
5
Maintainers
Readme
to-funcs
A very limited subset of to-* functions I use every day
Install
npm i to-funcs
Package on npm
API
toAscii(str)
Simplify a string by removing unsupported characters by the ASCII table
Swap when possible additional characters by their equivalent
For example
| Chars | Become | | :------ | :------- | | À Á Â Ã Ä Å | A | | ź ż ž | z | | « » “ ” 〝 〞 | " |
const toAscii = require('to-funcs/to-ascii')
// hello-world
toAscii('hêllø‐wörld')
// -
toAscii('💣-ؿ')
toBoolean(data, [fallback])
Check if data
is a String representation of a Boolean
If yes, convert and return the boolean value otherwise return fallback
If data
is already a boolean, return data
| Argument | Action |
| :------ | :------- |
| data | the tested data
|
| fallback | optional fallback
, default to undefined
. Must be a boolean
|
const toBoolean = require('to-funcs/to-boolean')
// true
toBoolean('true')
// undefined
toBoolean('123')
// false
toBoolean('123', false)
// false
toBoolean(false)
toCamelCase(str)
Convert a string to a camel case
The string is simplified with toAscii
const toCamelCase = require('to-funcs/to-camel-case')
// helloWorld
toCamelCase('hêllø‐wörld')
toNumber(data, [fallback])
Check if data
is a String representation of a Number
If yes, convert and return the numeric value otherwise return fallback
Check also if data
is a simple Math expression
If yes, evaluate it and return the numeric value otherwise return fallback
Accepted expressions are:
number
+number
number
-number
number
*number
number
/number
If data
is already a number, return data
| Argument | Action |
| :------ | :------- |
| data | the tested data
|
| fallback | optional fallback
, default to undefined
. Must be a number
|
const toNumber = require('to-funcs/to-number')
// 1.23
toNumber('1.23')
// undefined
toNumber('0.1s')
// 1
toNumber('3.45s', 1)
// -1.23
toNumber(-1.23)
// 3
toNumber('1 + 2')
// .5
toNumber('.1 / .2')
toSlugCase(str)
Convert a string to a slug case
The string is simplified with toAscii
const toSlugCase = require('to-funcs/to-slug-case')
// hello-world
toSlugCase('hêlløWörld')
// hello-world
toSlugCase('Hêllø Wörld')
Thanks
Mainly forked / inspired on
Tips / help from
License
MIT