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

greylist

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

greylist - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

61

index.js

@@ -10,4 +10,4 @@ 'use strict';

function GreyList(options) {
this.white = arrayify(options && options.white);
this.black = arrayify(options && options.black);
this.white = getFlatArrayOfRegexAndOrString(options && options.white);
this.black = getFlatArrayOfRegexAndOrString(options && options.black);
}

@@ -29,32 +29,43 @@

// Passes through `undefined` else converts to array of strings and/or `RegExp` objects.
function arrayify(list) {
if (list !== undefined) {
// if an object, get its enumerable defined keys
if (Object.prototype.toString.call(list) === '[object Object]') {
list = Object.keys(list).filter(function(item) {
return list[item] !== undefined;
});
function getFlatArrayOfRegexAndOrString(array, flat) {
if (!flat) {
// this is the top-level (non-recursed) call so intialize:
// `undefined` passes through without being converted to an array
if (array === undefined) {
return;
}
// make sure it's an array
if (!Array.isArray(list)) {
list = [list];
// arrayify given scalar string, regex, or object
if (!Array.isArray(array)) {
array = [array];
}
// initialize flat
flat = [];
}
array.forEach(function (item) {
// make sure all elements are either string or RegExp
list = list.map(function(item) {
switch (Object.prototype.toString.call(item)) {
case '[object String]':
case '[object RegExp]':
break;
default:
item = Object.prototype.toString.call(item);
}
return item;
});
}
return list;
switch (Object.prototype.toString.call(item)) {
case '[object String]':
case '[object RegExp]':
flat.push(item);
break;
case '[object Object]':
// recurse on complex item (when an object or array)
if (!Array.isArray(item)) {
// convert object into an array (of it's enumerable keys, but only when not undefined)
item = Object.keys(item).filter(function (key) { return item[key] !== undefined; });
}
getFlatArrayOfRegexAndOrString(item, flat);
break;
default:
flat.push(item + ''); // convert to string
}
});
return flat;
}
module.exports = GreyList;
{
"name": "greylist",
"version": "2.0.2",
"version": "2.1.0",
"description": "Flexible whitelist/blacklist testing",

@@ -5,0 +5,0 @@ "main": "index.js",

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