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

mcgorgeous

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

mcgorgeous - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

dist/mcgorgeous.esm.js

234

dist/mcgorgeous.min.js

@@ -1,233 +0,1 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.mcgorgeous = factory());
}(this, function () { 'use strict';
function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
/* @flow */
var emptyObject = Object.freeze({}); // These helpers produce better VM code in JS engines due to their
/**
* Quick object check - this is primarily used to tell
* Objects from primitive values when we know the value
* is a JSON-compliant type.
*/
function isObject(obj) {
return obj !== null && _typeof(obj) === "object";
}
/**
* Get the raw type string of a value, e.g., [object Object].
*/
var _toString = Object.prototype.toString;
/**
* Strict object type check. Only returns true
* for plain JavaScript objects.
*/
function isPlainObject(obj) {
return _toString.call(obj) === "[object Object]";
}
/**
* Make a map and return a function for checking if a key
* is in that map.
*/
function makeMap(str, expectsLowerCase) {
var map = Object.create(null);
var list = str.split(",");
for (var i = 0; i < list.length; i++) {
map[list[i]] = true;
}
return expectsLowerCase ? function (val) {
return map[val.toLowerCase()];
} : function (val) {
return map[val];
};
}
/**
* Check if a tag is a built-in tag.
*/
var isBuiltInTag = makeMap("slot,component", true);
/**
* Check if an attribute is a reserved attribute.
*/
var isReservedAttribute = makeMap("key,ref,slot,slot-scope,is");
/**
* Simple bind polyfill for environments that do not support it,
* e.g., PhantomJS 1.x. Technically, we don't need this anymore
* since native bind is now performant enough in most browsers.
* But removing it would mean breaking code that was able to run in
* PhantomJS 1.x, so this must be kept for backward compatibility.
*/
/* istanbul ignore next */
function polyfillBind(fn, ctx) {
function boundFn(a) {
var l = arguments.length;
return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
}
boundFn._length = fn.length;
return boundFn;
}
function nativeBind(fn, ctx) {
return fn.bind(ctx);
}
var bind = Function.prototype.bind ? nativeBind : polyfillBind;
/**
* Check if two values are loosely equal - that is,
* if they are plain objects, do they have the same shape?
*/
function looseEqual(a, b) {
if (a === b) return true;
var isObjectA = isObject(a);
var isObjectB = isObject(b);
if (isObjectA && isObjectB) {
try {
var isArrayA = Array.isArray(a);
var isArrayB = Array.isArray(b);
if (isArrayA && isArrayB) {
return a.length === b.length && a.every(function (e, i) {
return looseEqual(e, b[i]);
});
} else if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime();
} else if (!isArrayA && !isArrayB) {
var keysA = Object.keys(a);
var keysB = Object.keys(b);
return keysA.length === keysB.length && keysA.every(function (key) {
return looseEqual(a[key], b[key]);
});
} else {
/* istanbul ignore next */
return false;
}
} catch (e) {
/* istanbul ignore next */
return false;
}
} else if (!isObjectA && !isObjectB) {
return String(a) === String(b);
} else {
return false;
}
}
function isBoolean(b) {
return b === true || b === false;
}
function isNumber(n) {
return typeof n == "number";
}
function isString(x) {
return Object.prototype.toString.call(x) === "[object String]";
}
function arrayDifference(arr1, arr2) {
return arr1.filter(function (x) {
return !arr2.includes(x);
});
}
function checkObjectSchema(schema, obj) {
return _traverseObjects(schema, obj);
} // similar to VueJS traverse https://github.com/vuejs/vue/blob/52719ccab8fccffbdf497b96d3731dc86f04c1ce/src/core/observer/traverse.js#L19
// JSON data won't be cyclical so we don't need to do id checking
function _traverseObjects(val1, val2) {
var isO1 = isPlainObject(val1);
var isO2 = isPlainObject(val2);
var isA1 = Array.isArray(val1);
var isA2 = Array.isArray(val2);
var i, keys1, keys2;
if (isA1) {
if (!isA2) {
throw Error("Schema is looking for \"array\", data is ".concat(JSON.stringify(val2)));
}
i = val2.length;
while (i--) {
_traverseObjects(val1[0], val2[i]);
}
} else if (isO1) {
if (!isO2) {
throw Error("Schema is looking for \"object\", data is ".concat(JSON.stringify(val2)));
} //loop object
keys1 = Object.keys(val1).sort();
keys2 = Object.keys(val2).sort();
if (!looseEqual(keys1, keys2)) {
throw Error("Keys in schema don't match keys in data: ".concat(JSON.stringify(arrayDifference(keys1, keys2))));
}
i = keys1.length;
while (i--) {
_traverseObjects(val1[keys1[i]], val2[keys2[i]]);
}
} else {
switch (val1) {
case "string":
if (!isString(val2)) {
throw Error("\"".concat(val2, "\" is not a string."));
}
break;
case 0:
if (!isNumber(val2)) {
throw Error("\"".concat(val2, "\" is not a number."));
}
break;
case true:
if (!isBoolean(val2)) {
throw Error("\"".concat(val2, "\" is not a boolean."));
}
break;
}
}
return true;
}
function index (schema, data) {
/**
* {prop: type} e.g.
* {name: String}
**/
return checkObjectSchema(schema, data);
}
return index;
}));
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t=t||self).mcgorgeous=r()}(this,function(){"use strict";function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.freeze({});function a(t){return null!==t&&"object"===r(t)}var e=Object.prototype.toString;function b(t){return"[object Object]"===e.call(t)}function t(t,r){for(var e=Object.create(null),n=t.split(","),o=0;o<n.length;o++)e[n[o]]=!0;return r?function(t){return e[t.toLowerCase()]}:function(t){return e[t]}}t("slot,component",!0),t("key,ref,slot,slot-scope,is");Function.prototype.bind;function g(r,e){if(r===e)return!0;var t=a(r),n=a(e);if(!t||!n)return!t&&!n&&String(r)===String(e);try{var o=Array.isArray(r),i=Array.isArray(e);if(o&&i)return r.length===e.length&&r.every(function(t,r){return g(t,e[r])});if(r instanceof Date&&e instanceof Date)return r.getTime()===e.getTime();if(o||i)return!1;var c=Object.keys(r),f=Object.keys(e);return c.length===f.length&&c.every(function(t){return g(r[t],e[t])})}catch(t){return!1}}function n(t,r){return function t(r,e){var n=b(r);var o=b(e);var i=Array.isArray(r);var c=Array.isArray(e);var f,a,u;if(i){if(!c)throw Error('Schema is looking for "array", data is '.concat(JSON.stringify(e)));for(f=e.length;f--;)t(r[0],e[f])}else if(n){if(!o)throw Error('Schema is looking for "object", data is '.concat(JSON.stringify(e)));if(a=Object.keys(r).sort(),u=Object.keys(e).sort(),!g(a,u))throw Error("Keys in schema don't match keys in data: ".concat(JSON.stringify((l=u,a.filter(function(t){return!l.includes(t)})))));for(f=a.length;f--;)t(r[a[f]],e[u[f]])}else switch(r){case"string":if(y=e,"[object String]"!==Object.prototype.toString.call(y))throw Error('"'.concat(e,'" is not a string.'));break;case 0:if("number"!=typeof e)throw Error('"'.concat(e,'" is not a number.'));break;case!0:if(!0!==(s=e)&&!1!==s)throw Error('"'.concat(e,'" is not a boolean.'))}var s;var y;var l;return!0}(t,r)}return function(t,r){return n(t,r)}});
{
"name": "mcgorgeous",
"version": "0.0.4",
"version": "0.0.5",
"description": "Checks schema of JSON return types",
"main": "./src/index.js",
"main": "./dist/mcgorgeous.common.js",
"module": "./dist/mcgorgeous.esm.js",
"unpkg": "./dist/mcgorgeous.js",
"jsdelivr": "./dist/mcgorgeous.js",
"files": [
"src",
"dist/*.js"
],
"scripts": {

@@ -33,4 +40,6 @@ "lint": "prettier --write \"{./test.js,./src/*.js,./src/**/*.js}\"",

"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-node-resolve": "^5.2.0"
}
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-uglify": "^6.0.2"
},
"dependencies": {}
}
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