New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ifonly

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ifonly - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

84

index.js

@@ -1,54 +0,56 @@

var ifonly = function (obj, keys, ignore) {
var state, key;
var isEmpty = function (some) {
if (some == null || typeof some === 'undefined') {
return true;
}
;(function () {
var only = function (obj, keys, ignore) {
var state, key;
var isEmpty = function (some) {
if (some == null || typeof some === 'undefined') {
return true;
}
if (some instanceof Array || typeof some === 'string') {
return some.length === 0;
}
if (some instanceof Array || typeof some === 'string') {
return some.length === 0;
}
for (var k in some) {
if (some.hasOwnProperty(k)) {
return false;
}
}
for (var k in some) {
if (some.hasOwnProperty(k)) {
return false;
}
}
return true;
};
ignore = ignore || [];
return true;
};
ignore = ignore || [];
for (key in obj) {
if (obj.hasOwnProperty(key)) {
// if current key is in ignore list
if (ignore.indexOf(key) !== -1) {
continue;
}
for (key in obj) {
if (obj.hasOwnProperty(key)) {
// if current key is in ignore list
if (ignore.indexOf(key) !== -1) {
continue;
}
// if there is other key in obj which is not empty
if (keys.indexOf(key) === -1 && !isEmpty(obj[key])) {
state = false;
break;
}
// if there is other key in obj which is not empty
if (keys.indexOf(key) === -1 && !isEmpty(obj[key])) {
state = false;
break;
}
// if current key is required and not empty
if (keys.indexOf(key) !== -1 && !isEmpty(obj[key])) {
state = true;
}
// if current key is required and not empty
if (keys.indexOf(key) !== -1 && !isEmpty(obj[key])) {
state = true;
}
// if current key is required but it's empty
if (keys.indexOf(key) !== -1 && isEmpty(obj[key])) {
state = false;
// if current key is required but it's empty
if (keys.indexOf(key) !== -1 && isEmpty(obj[key])) {
state = false;
}
}
}
}
return state;
};
return state;
};
if (typeof module !== 'undefined' && module.exports) {
module.exports = ifonly;
if (typeof module !== 'undefined' && module.exports) {
module.exports = only;
} else {
window.ifonly = ifonly;
window.only = only;
}
})();
{
"name": "ifonly",
"version": "1.0.0",
"version": "1.1.0",
"description": "ifonly is function that checks if your object have only and only specific properties you passed.",

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

@@ -15,15 +15,15 @@ # ifonly

obj = { a: 'a'};
console.log(ifonly(obj, ['a'])); // true because only 'a' property is present
console.log(only(obj, ['a'])); // true because only 'a' property is present
obj = { a: 'a', b: 'b', c: 'c' };
console.log(ifonly(obj, ['a', 'b'])); // false because 'c' property is present
console.log(only(obj, ['a', 'b'])); // false because 'c' property is present
obj = { a: 'a', b: 'b', c: 'c' };
console.log(ifonly(obj, ['a', 'b'], ['c'])); // true because 'c' property is ignored
console.log(only(obj, ['a', 'b'], ['c'])); // true because 'c' property is ignored
obj = { a: '', b: 'b', c: '' };
console.log(ifonly(obj, ['b'])); // true because 'a' and 'c' properties are empty
console.log(only(obj, ['b'])); // true because 'a' and 'c' properties are empty
obj = { a: [], b: 'b', c: {} };
console.log(ifonly(obj, ['b'])); // true because 'a' and 'c' properties are empty
console.log(only(obj, ['b'])); // true because 'a' and 'c' properties are empty
```
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