https://github.com/avoidwork/tiny-coerce
Tiny coercion library for Client or Server
https://github.com/avoidwork/tiny-coerce
Last synced: 10 months ago
JSON representation
Tiny coercion library for Client or Server
- Host: GitHub
- URL: https://github.com/avoidwork/tiny-coerce
- Owner: avoidwork
- License: bsd-3-clause
- Created: 2015-12-28T13:59:14.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-10-09T00:57:53.000Z (over 1 year ago)
- Last Synced: 2024-10-11T21:31:07.288Z (over 1 year ago)
- Language: JavaScript
- Homepage: http://avoidwork.github.io/tiny-coerce
- Size: 757 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 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
```javascript
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.
```console
-----------------|---------|----------|---------|---------|-------------------
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