Package detail

tiny-coerce

avoidwork206BSD-3-Clause3.0.2

Tiny coercion library for Client or Server

coerce, coercion

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

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

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

3.0.2

  • Bump rollup from 4.1.5 to 4.2.0 #11
  • Bump actions/setup-node from 3 to 4 #10
  • Bump rollup from 4.1.4 to 4.1.5 #9
  • Bump eslint from 8.51.0 to 8.52.0 #8
  • Bump rollup from 4.1.3 to 4.1.4 #7
  • Bump rollup from 4.0.2 to 4.1.3 #6
  • Lowering engines.node to >=6 for const 8546533
  • Generating CHANGELOG.md 9f0a97b
  • Generating ./types/coerce.d.ts d384209

3.0.1

10 October 2023

  • Bump rollup from 4.0.0 to 4.0.2 #5
  • Bump eslint from 8.50.0 to 8.51.0 #4
  • Bump rollup from 3.29.4 to 4.0.0 #3
  • Bump @rollup/plugin-terser from 0.4.3 to 0.4.4 #2
  • Adding .github directory 43e8a88
  • Adjusting tests 6d0b463
  • Setting extension of main to .cjs for deprecated tooling aacc656

3.0.0

4 October 2023

  • Updating dependencies, adding husky for precommit hook 550cafd
  • Updating dependencies, adding husky for precommit hook, updating tests, fixing an assignment error, creating constants, updating copyright years, updating README.md 81bf1e6
  • Generating CHANGELOG.md 04a0135

2.0.0

5 September 2022

  • Refactoring to ES module #1

1.1.1

8 July 2018

1.1.0

8 July 2018

  • Adding an optional second parameter for deep coercion, adding support for Java styled string booleans (True/False), setting minimum node.js engine version to 6.5.0, updating dependencies, dropping ES5 outputs 87b3212
  • Hardening regex.json & updating tests 790900c
  • Hardening regex.json, updating tests, updating README 6220199

1.0.1

28 December 2015

1.0.0

28 December 2015