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

typeof-arguments

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeof-arguments - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

15

index.js
const ofType = require('of-type');
const cliColor = require('cli-color');
const error = cliColor.red;
const warn = cliColor.bgYellow.black;
module.exports = function(a,o,c){
const errArguments = '\x1b[31mInvalid arguments. The first argument must indicate [Object Arguments] object.\x1b[0m';
const errTypes = '\x1b[31mInvalid arguments. The second argument must be of type [Array].\x1b[0m';
const errItems = '\x1b[31mInvalid arguments. Each item of the second [Array] argument must be of type [String|RegExp].\x1b[0m';
const errArguments = warn('typeof-arguments')+': '+error('Invalid module argument. The first argument must indicate [Object Arguments] object.');
const errTypes = warn('typeof-arguments')+': '+error('Invalid module argument. The second argument must be of type [Array].');
const errItems = warn('typeof-arguments')+': '+error('Invalid module argument. Each item of the second [Array] argument must be of type [String|RegExp].');
const isO = ofType(a,'arguments');

@@ -46,6 +48,7 @@ const isA = ofType(o,'array');

})();
var msg = `Invalid argument [${x}]. The [${act}] ${truthyFalsy}argument has been passed, while the ${isStr ? `[${exp}] one`:`argument of the type matching the regular expression: ${exp}`} is expected.`;
if(clb){
c(act,exp);
c(act,exp,msg);
} else {
var err = new TypeError(`\x1b[31mInvalid argument [${x}]. The [${act}] ${truthyFalsy}argument has been passed, while the ${isStr ? `[${exp}] one`:`argument of the type matching the regular expression: ${exp}`} is expected.\x1b[0m`);
var err = new TypeError(error(msg));
throw err;

@@ -52,0 +55,0 @@ }

{
"name": "typeof-arguments",
"version": "2.0.0",
"version": "2.1.0",
"description": "Validate the types of arguments passed to the function.",

@@ -20,4 +20,5 @@ "main": "index.js",

"dependencies": {
"of-type": "^1.0.6"
"of-type": "^1.0.6",
"cli-color": "^1.2.0"
}
}

17

readme.md
# Description
`typeof-arguments` is a module that validates arguments' types passed to the enclosing function.
* Any bugs found? Give me to know on **dev.rafalko@gmail.com**
* Any bugs found? Give me to know on dev.rafalko@gmail.com or on [GitHub](https://github.com/devrafalko/typeof-arguments)
* Also check out [**`of-type`**](https://www.npmjs.com/package/of-type) package that checks whether the given value is of particular type *(`typeof-arguments` is based on `of-type` package)*.

@@ -40,3 +40,3 @@

##### `callback` **[Function]** *(optional)*
* if **not passed**, the **TypeError** with **default message** will be printed to the console, if the argument passed to the function is invalid.
* if **not passed**, the **TypeError** with **default message** will be **thrown** to the console, if the argument passed to the function is invalid.
* The TypeError default message is eg.:

@@ -46,5 +46,9 @@ * `Invalid argument [0]. The [String] argument has been passed, while the [Number] one is expected.`

* `Invalid argument [1]. The [Number] <<truthy>> argument has been passed, while the [falsy|String] one is expected.`
* if **passed**, the default error message **will not** be printed to the console and the user can decide what to do inside the `callback` function
* if **passed**, the default TypeError **will not be thrown** to the console and the user can decide what to do inside the `callback` function.
* Use callback function if you don't want to stop your code execution by default *(no callback)* **`throw`** statement!
* the `callback` function is executed **only** if at least one argument passed through the enclosing function is of invalid type.
* the parameter **`actual`** [String] and **`expected`** [String] is passed through the callback function. The parameter `actual` indicates the actual type of the argument passed through the enclosing function, eg. `'[String]'`, when the `expected` parameter indicates the type(s) expected by the user, eg. `'[Array]'`, `'[Boolean|Number]'`, `/array|object/i`.
* the parameter **`actual`** [String], **`expected`** [String] and **msg** [String] is passed through the callback function:
* `actual` indicates the actual type of the argument passed through the enclosing function, eg. `'[String]'`
* `expected` indicates the type(s) expected by the user, eg. `'[Array]'`, `'[Boolean|Number]'`, `/array|object/i`
* `msg` is the default error [String] message, that you can use for example to throw an error in the callback function

@@ -57,4 +61,5 @@ ```javascript

function hello(paramA,paramB){
args(arguments,['any','string|number'],(actual,expected)=>{
console.log(new Error(`Not good! You passed ${actual}, when you should have passed ${expected}.`));
args(arguments,['any','string|number'],(actual,expected,msg)=>{
console.error(msg);
//throw new Error("Aborted! " + msg);
});

@@ -61,0 +66,0 @@ }

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