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

types.js

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

types.js - npm Package Compare versions

Comparing version 1.3.9 to 1.4.0

2

package.json
{
"name": "types.js",
"version": "1.3.9",
"version": "1.4.0",
"description": "A tiny (1.8kb), but essential Javascript type-check library",

@@ -5,0 +5,0 @@ "main": "types.min.js",

@@ -158,9 +158,15 @@ types.js

Returns value if it is a Number or convertable to a Number. Returns replacement if value is invalid or not convertable.
Returns a Number object with a .void property set to true if no valid value and replacement were given or no conversion was possible.
Returns a Number object with a .void property set to true if no valid value and replacement were given and
conversion was not possible.
You can check yourNumber.void to see if yourNumber is set to a valid number. If .void is true, yourNumber is not set to a
number, but to a Number object which is ready for mathemetical operation, and defaults to 0.
You can check value.void to see if value is ready to be fetched. If value.void is true, you can only fetch it's
default value by doing some mathematical operation on it like: `value+ 0`, otherwise you'll get an object. After
any mathematical operation on value, value.void will be undefined and value has become a 'real' number.
If value.void is true, the default value returned with `value+ 0` is 0.
`Types.typeof( Types.forceNumber() );` returns 'number', as it is a Number and you can use it as number.
If you want to be sure that forceNumber returns a 'real' number, then simply supply a 'real' number replacement,
like: `var nr= _.forceNumber(nr, 0);`, and it will never return the Number-object form.
`Types.typeof( nr= Types.forceNumber() );` returns 'number', also if `nr.void === true`
Example: make a numberFilter for arguments with the new forceNumber:

@@ -179,8 +185,8 @@ ```javascript

function someFunc(){
function forceArgsToNumber(){
return numberFilter.apply( this, arguments );
}
console.log( someFunc('ignore', 1, 'the', 2, 'strings!', 3) );
console.log( forceArgsToNumber('ignore', 1, 'the', 2, 'strings!', 3) );
// [ 1, 2, 3 ]
console.log( someFunc('1 but', '2 not', '3 unconditional!') );
console.log( forceArgsToNumber('1 but', '2 not', '3 unconditional!') );
// [ 1, 2, 3 ]

@@ -187,0 +193,0 @@ ```

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