3.0.2 • Published 6 months ago

tiny-coerce v3.0.2

Weekly downloads
20
License
BSD-3-Clause
Repository
github
Last release
6 months ago

Tiny Coerce

String to primitive coercion for Client or Server. It's great for DOM data attributes, localStorage, and other cases where your need to store a String.

Using the function

import {coerce} from "tiny-coerce";

console.log(coerce("true")); // true
console.log(coerce("null")); // null
console.log(coerce({a: {b: "50"}}, true).a.b) // 50

Testing

Tiny Coerce has 100% code coverage with its tests.

-----------------|---------|----------|---------|---------|-------------------
File             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|-------------------
All files        |     100 |     86.2 |     100 |     100 |                  
 tiny-coerce.cjs |     100 |     86.2 |     100 |     100 | 22-24,36         
-----------------|---------|----------|---------|---------|-------------------

API

coerce (arg, deep = false)

Returns a coercion of arg. Deep coercion is optional with the second parameter.

First parameter is trimmed before coercion!

License

Copyright (c) 2023 Jason Mulligan Licensed under the BSD-3 license

3.0.2

6 months ago

3.0.1

7 months ago

3.0.0

7 months ago

2.0.0

2 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

8 years ago

1.0.0

8 years ago