Socket
Socket
Sign inDemoInstall

is-natural-number

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 4.0.0

26

index.js

@@ -7,4 +7,26 @@ /*!

module.exports = function isNaturalNumber(val, zero) {
return val >= (zero ? 0 : 1) && Number.isSafeInteger(val);
module.exports = function isNaturalNumber(val, option) {
if (option) {
if (typeof option !== 'object') {
throw new TypeError(
String(option) +
' is not an object. Expected an object that has boolean `includeZero` property.'
);
}
if ('includeZero' in option) {
if (typeof option.includeZero !== 'boolean') {
throw new TypeError(
String(option.includeZero) +
' is neither true nor false. `includeZero` option must be a Boolean value.'
);
}
if (option.includeZero && val === 0) {
return true;
}
}
}
return val >= 1 && Number.isSafeInteger(val);
};

@@ -5,4 +5,26 @@ /*!

*/
export default function isNaturalNumber(val, zero) {
return val >= (zero ? 0 : 1) && Number.isSafeInteger(val);
export default function isNaturalNumber(val, option) {
if (option) {
if (typeof option !== 'object') {
throw new TypeError(
String(option) +
' is not an object. Expected an object that has boolean `includeZero` property.'
);
}
if ('includeZero' in option) {
if (typeof option.includeZero !== 'boolean') {
throw new TypeError(
String(option.includeZero) +
' is neither true nor false. `includeZero` option must be a Boolean value.'
);
}
if (option.includeZero && val === 0) {
return true;
}
}
}
return val >= 1 && Number.isSafeInteger(val);
}

2

package.json
{
"name": "is-natural-number",
"version": "3.0.0",
"version": "4.0.0",
"description": "Check if a value is a natural number",

@@ -5,0 +5,0 @@ "repository": "shinnn/is-natural-number.js",

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc