# to-funcs

> A very limited subset of to-* functions I use every day

Latest version **0.4.0** (published 2016-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install to-funcs
pnpm add to-funcs
yarn add to-funcs
bun add to-funcs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2016-08-05 |
| First published | 2016-06-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jérôme Decoster |
| Maintainers | jeromedecoster |
| Keywords | ascii, boolean, camelcase, camel case, convert, slugcase, slug case, string, number |

## Links

- npm: https://www.npmjs.com/package/to-funcs
- Repository: https://github.com/jeromedecoster/to-funcs
- Homepage: https://github.com/jeromedecoster/to-funcs#readme
- Issues: https://github.com/jeromedecoster/to-funcs/issues
- npm.io page: https://npm.io/package/to-funcs

## Dependencies (1)

- [is-funcs](https://npm.io/package/is-funcs.md) ^0.5.1

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.4.0 (latest) — 2016-08-05
- 0.3.1 — 2016-08-05
- 0.3.0 — 2016-07-13
- 0.2.0 — 2016-07-06
- 0.1.0 — 2016-07-01
- 0.0.0 — 2016-06-24

## README

# to-funcs

> A very limited subset of to-* functions I use every day

## Install

```bash
npm i to-funcs
```

Package [on npm](https://www.npmjs.com/package/to-funcs)

## API

* [toAscii](#toasciistr)
* [toBoolean](#tobooleandata-fallback)
* [toCamelCase](#tocamelcasestr)
* [toNumber](#tonumberdata-fallback)
* [toSlugCase](#toslugcasestr)

#### 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 |
| **« » “ ” 〝 〞** | " |


```js
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` |

```js
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](#toasciistr)

```js
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` |

```js
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](#toasciistr)

```js
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
- [camelcase](https://github.com/sindresorhus/camelcase)
- [eval-expression](https://github.com/tomekwi/eval-expression.js)
- [to-camel-case](https://github.com/ianstormtaylor/to-camel-case)
- [to-slug-case](https://github.com/ianstormtaylor/to-slug-case)

Tips / help from
- [codetable](http://www.codetable.net/decimal/197)
- [deburr](https://github.com/smikhalevski/deburr/blob/master/src/deburr.json)
- [typeit](http://swedish.typeit.org)
- [wikipedia](https://en.wikipedia.org/wiki/Latin_Extended-A)

## License

MIT

---
_Source: https://npm.io/package/to-funcs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
