Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tiny-coerce

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-coerce - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

dist/tiny-coerce.umd.js

17

dist/tiny-coerce.js
/**
* tiny-coerce
*
* @copyright 2022 Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 2.0.0
* @version 3.0.0
*/
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.tinyCoerce={}));})(this,(function(exports){'use strict';const regex = {
const regex = {
false: /^(F|f)alse$/,

@@ -13,7 +13,8 @@ null: /^(N|n)ull$/,

true: /^(T|t)rue$/
};function walk (arg) {
};const STRING = "string";
const UNDEFINED = "undefined";function walk (arg) {
const array = Array.isArray(arg),
x = array ? arg : Object.keys(arg),
fn = (i, idx) => {
arg[array ? i : idx] = coerce(array ? i : arg[i], true); // eslint-disable-line no-use-before-define
arg[array ? idx : i] = coerce(array ? i : arg[i], true); // eslint-disable-line no-use-before-define
};

@@ -27,3 +28,3 @@

if (typeof arg !== "string") {
if (typeof arg !== STRING) {
result = arg;

@@ -46,3 +47,3 @@

result = null;
} else if (value === "undefined") {
} else if (value === UNDEFINED) {
result = undefined;

@@ -71,2 +72,2 @@ } else if (!isNaN(tmp = Number(value))) {

return result;
}exports.coerce=coerce;Object.defineProperty(exports,'__esModule',{value:true});}));
}export{coerce};
/*!
2022 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 2.0.0
2023 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 3.0.0
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).tinyCoerce={})}(this,(function(e){"use strict";const t={false:/^(F|f)alse$/,null:/^(N|n)ull$/,json:/^["\[{].*[}\]"]$/,true:/^(T|t)rue$/};function s(e){const t=Array.isArray(e);(t?e:Object.keys(e)).forEach(((s,l)=>{e[t?s:l]=n(t?s:e[s],!0)}))}function n(e,n=!1){let l;if("string"!=typeof e)l=e,n&&s(l);else{const f=e.trim();let i;if(0===f.length)l=f;else if(t.true.test(f))l=!0;else if(t.false.test(f))l=!1;else if(t.null.test(f))l=null;else if("undefined"===f)l=void 0;else if(isNaN(i=Number(f)))if(t.json.test(f)){let e;try{l=JSON.parse(f),e=!0}catch(t){l=f,e=!1}e&&n&&s(l)}else l=f;else l=i}return l}e.coerce=n,Object.defineProperty(e,"__esModule",{value:!0})}));//# sourceMappingURL=tiny-coerce.min.js.map
const e={false:/^(F|f)alse$/,null:/^(N|n)ull$/,json:/^["\[{].*[}\]"]$/,true:/^(T|t)rue$/},t="string",s="undefined";function l(e){const t=Array.isArray(e);(t?e:Object.keys(e)).forEach(((s,l)=>{e[t?l:s]=n(t?s:e[s],!0)}))}function n(n,f=!1){let i;if(typeof n!==t)i=n,f&&l(i);else{const t=n.trim();let r;if(0===t.length)i=t;else if(e.true.test(t))i=!0;else if(e.false.test(t))i=!1;else if(e.null.test(t))i=null;else if(t===s)i=void 0;else if(isNaN(r=Number(t)))if(e.json.test(t)){let e;try{i=JSON.parse(t),e=!0}catch(s){i=t,e=!1}e&&f&&l(i)}else i=t;else i=r}return i}export{n as coerce};//# sourceMappingURL=tiny-coerce.min.js.map
{
"name": "tiny-coerce",
"version": "2.0.0",
"version": "3.0.0",
"description": "Tiny coercion library for Client or Server",
"type": "module",
"types": "types/coerce.d.ts",
"source": "src/coerce.js",
"main": "dist/tiny-coerce.cjs",
"module": "dist/tiny-coerce.esm.js",
"type": "module",
"sourceType": "module",
"engineStrict": true,
"main": "dist/tiny-coerce",
"exports": {
"types": "./types/coerce.d.ts",
"import": "./dist/tiny-coerce.js",
"require": "./dist/tiny-coerce.cjs"
},
"files": [
"dist",
"types"
],
"engines": {
"node": ">= 16.0.0"
"node": ">=12"
},
"engineStrict": true,
"scripts": {
"build": "npm run lint && rm -rf dist/* && npm run rollup && npm run mocha",
"build": "npm run lint && rm -rf dist && npm run rollup",
"changelog": "auto-changelog -p",
"rollup": "rollup --config",
"fix": "eslint --fix *.js src/*.js test/*.js",
"lint": "eslint *.js src/*.js test/*.js",
"mocha": "mocha test/*.js",
"test": "npm run lint && npm run mocha"
"mocha": "nyc mocha test/*.js",
"types": "npx -p typescript tsc src/httptest.js --declaration --allowJs --emitDeclarationOnly --outDir types",
"test": "npm run lint && npm run mocha",
"prepare": "husky install"
},

@@ -37,9 +48,12 @@ "repository": {

"devDependencies": {
"@rollup/plugin-terser": "^0.4.3",
"auto-changelog": "^2.4.0",
"eslint": "^8.23.0",
"mocha": "^10.0.0",
"rollup": "^2.79.0",
"rollup-plugin-terser": "^7.0.2"
"eslint": "^8.49.0",
"husky": "^8.0.3",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"rollup": "^3.29.2",
"typescript": "^5.2.2"
},
"dependencies": {}
}

@@ -6,9 +6,4 @@ # Tiny Coerce

## API
##### coerce (arg[, deep = false])
Returns a coercion of `arg`. Deep coercion is optional with the second parameter.
## Using the function
First parameter is trimmed before coercion!
## Example
```javascript

@@ -22,7 +17,24 @@ import {coerce} from "tiny-coerce";

## How can I load dom-router?
When loaded with a script tag, `window.tinyCoerce.coerce()` will be created.
## 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) 2022 Jason Mulligan
Copyright (c) 2023 Jason Mulligan
Licensed under the BSD-3 license

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc