Git Product home page Git Product logo

to-funcs's Introduction

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

to-funcs's People

Contributors

jeromedecoster avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.