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

fn-args

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fn-args - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

index.d.ts

42

index.js

@@ -7,9 +7,9 @@ 'use strict';

const reComments = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
const commentRegex = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
const quotes = ['`', '"', '\''];
const fnNC = fn.toString().replace(reComments, ''); // Function with no comments
const functionSource = fn.toString().replace(commentRegex, ''); // Function with no comments
let depth = 0; // () [] {}
let fnND = ''; // Function with no default values
let fnNoDefaults = ''; // Function with no default values
let i = 0;

@@ -21,7 +21,7 @@

// Remove default values
for (; i < fnNC.length && fnNC.charAt(i) !== ')'; i += 1) {
for (; i < functionSource.length && functionSource.charAt(i) !== ')'; i += 1) {
// Exiting if an arrow occurs. Needed when arrow function without '()'.
if (fnNC.startsWith('=>', i)) {
fnND = fnNC;
i = fnNC.length;
if (functionSource.startsWith('=>', i)) {
fnNoDefaults = functionSource;
i = functionSource.length;
break;

@@ -31,4 +31,4 @@ }

// If we found a default value - skip it
if (fnNC.charAt(i) === '=') {
for (; i < fnNC.length && ((fnNC.charAt(i) !== ',' && fnNC.charAt(i) !== ')') || depth !== 0); i += 1) {
if (functionSource.charAt(i) === '=') {
for (; i < functionSource.length && ((functionSource.charAt(i) !== ',' && functionSource.charAt(i) !== ')') || depth !== 0); i += 1) {
// Skip all quotes

@@ -38,6 +38,6 @@ let wasQuote = false;

for (let j = 0; j < quotes.length; j += 1) {
if (fnNC.charAt(i) === quotes[j]) {
if (functionSource.charAt(i) === quotes[j]) {
i += 1;
for (; i < fnNC.length && fnNC.charAt(i) !== quotes[j];) {
for (; i < functionSource.length && functionSource.charAt(i) !== quotes[j];) {
i += 1;

@@ -56,3 +56,3 @@ }

switch (fnNC.charAt(i)) { // Keeps correct depths of all types of parenthesises
switch (functionSource.charAt(i)) { // Keeps correct depths of all types of parenthesises
case '(':

@@ -72,17 +72,17 @@ case '[':

if (fnNC.charAt(i) === ',') {
fnND += ',';
if (functionSource.charAt(i) === ',') {
fnNoDefaults += ',';
}
if (fnNC.charAt(i) === ')') { // Quits from the cycle immediately
fnND += ')';
if (functionSource.charAt(i) === ')') { // Quits from the cycle immediately
fnNoDefaults += ')';
break;
}
} else {
fnND += fnNC.charAt(i);
fnNoDefaults += functionSource.charAt(i);
}
}
if (i < fnNC.length && fnNC.charAt(i) === ')') {
fnND += ')';
if (i < functionSource.length && functionSource.charAt(i) === ')') {
fnNoDefaults += ')';
}

@@ -92,7 +92,7 @@

// The second part matches the rest
const reFnArgs = /^(?:async)?([^=()]+)=|\(([^)]+)\)/;
const regexFnArguments = /^(?:async)?([^=()]+)=|\(([^)]+)\)/;
const match = reFnArgs.exec(fnND);
const match = regexFnArguments.exec(fnNoDefaults);
return match ? (match[1] || match[2]).split(',').map(x => x.trim()).filter(Boolean) : [];
};
{
"name": "fn-args",
"version": "4.0.0",
"version": "5.0.0",
"description": "Get the arguments of a function, arrow function, generator function, async function",

@@ -13,9 +13,10 @@ "license": "MIT",

"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava test.js"
"test": "xo && ava test.js && tsd"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],

@@ -25,5 +26,2 @@ "keywords": [

"arguments",
"fn",
"func",
"args",
"tostring",

@@ -37,5 +35,6 @@ "extract",

"devDependencies": {
"ava": "^1.2.0",
"esm": "^3.2.0",
"semver": "^5.3.0",
"ava": "^1.4.1",
"esm": "^3.2.22",
"semver": "^6.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"

@@ -42,0 +41,0 @@ },

@@ -16,14 +16,14 @@ # fn-args [![Build Status](https://travis-ci.org/sindresorhus/fn-args.svg?branch=master)](https://travis-ci.org/sindresorhus/fn-args)

```js
const fnArgs = require('fn-args');
const functionArguments = require('fn-args');
fnArgs(function (foo, bar) {});
functionArguments(function (foo, bar) {});
//=> ['foo', 'bar']
fnArgs((foo, bar) => {});
functionArguments((foo, bar) => {});
//=> ['foo', 'bar']
fnArgs(function * (foo, bar) {});
functionArguments(function * (foo, bar) {});
//=> ['foo', 'bar']
fnArgs(async function (foo, bar) {});
functionArguments(async function (foo, bar) {});
//=> ['foo', 'bar']

@@ -30,0 +30,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