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

normalizr

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalizr - npm Package Compare versions

Comparing version 3.0.0-beta to 3.0.0-beta.2

index.d.ts

21

dist/index.js

@@ -167,5 +167,4 @@ 'use strict';

var keyIsFunction = typeof key === 'function';
if (!key || typeof key !== 'string' && !keyIsFunction) {
throw new Error('A string or function is required to return the entity key.');
if (!key || typeof key !== 'string') {
throw new Error('Expected a string key for Entity, but found ' + key + '.');
}

@@ -185,5 +184,3 @@

this._getKey = keyIsFunction ? key : function () {
return key;
};
this._key = key;
this._getId = typeof idAttribute === 'function' ? idAttribute : function (input) {

@@ -198,7 +195,2 @@ return input[idAttribute];

createClass(EntitySchema, [{
key: 'getKey',
value: function getKey(input, parent, key) {
return this._getKey(input, parent, key);
}
}, {
key: 'define',

@@ -237,2 +229,7 @@ value: function define(definition) {

}
}, {
key: 'key',
get: function get() {
return this._key;
}
}]);

@@ -443,3 +440,3 @@ return EntitySchema;

return function (schema, processedEntity, value, parent, key) {
var schemaKey = schema.getKey(value, parent, key);
var schemaKey = schema.key;
var id = schema.getId(value, parent, key);

@@ -446,0 +443,0 @@ if (!(schemaKey in entities)) {

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),defineProperty=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},get$1=function e(t,n,r){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(void 0===i){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,r)}if("value"in i)return i.value;var a=i.get;if(void 0!==a)return a.call(r)},inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},set=function e(t,n,r,i){var o=Object.getOwnPropertyDescriptor(t,n);if(void 0===o){var a=Object.getPrototypeOf(t);null!==a&&e(a,n,r,i)}else if("value"in o&&o.writable)o.value=r;else{var u=o.set;void 0!==u&&u.call(i,r)}return r},EntitySchema=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};classCallCheck(this,e);var i="function"==typeof t;if(!t||"string"!=typeof t&&!i)throw new Error("A string or function is required to return the entity key.");var o=r.idAttribute,a=void 0===o?"id":o,u=r.mergeStrategy,c=void 0===u?function(e,t){return _extends({},e,t)}:u,s=r.processStrategy,l=void 0===s?function(e){return _extends({},e)}:s;this._getKey=i?t:function(){return t},this._getId="function"==typeof a?a:function(e){return e[a]},this._mergeStrategy=c,this._processStrategy=l,this.define(n)}return createClass(e,[{key:"getKey",value:function(e,t,n){return this._getKey(e,t,n)}},{key:"define",value:function(e){this.schema=Object.keys(e).reduce(function(t,n){var r=e[n];return _extends({},t,defineProperty({},n,r))},this.schema||{})}},{key:"getId",value:function(e,t,n){return this._getId(e,t,n)}},{key:"merge",value:function(e,t){return this._mergeStrategy(e,t)}},{key:"normalize",value:function(e,t,n,r,i){var o=this,a=this._processStrategy(e,t,n);return Object.keys(this.schema).forEach(function(e){if(a.hasOwnProperty(e)&&"object"===_typeof(a[e])){var t=o.schema[e];a[e]=r(a[e],a,e,t,i)}}),i(this,a,e,t,n),this.getId(e,t,n)}}]),e}(),PolymorphicSchema=function(){function e(t,n){classCallCheck(this,e),n&&(this._schemaAttribute="string"==typeof n?function(e){return e[n]}:n),this.define(t)}return createClass(e,[{key:"define",value:function(e){this.schema=e}},{key:"getSchemaAttribute",value:function(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}},{key:"inferSchema",value:function(e,t,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(e,t,n),i=this.schema[r];if(!i)throw new Error('No schema found for attribute "'+r+'".');return i}},{key:"normalizeValue",value:function(e,t,n,r,i){var o=this.inferSchema(e,t,n),a=r(e,t,n,o,i);return this.isSingleSchema||void 0===a||null===a?a:{id:a,schema:this.getSchemaAttribute(e,t,n)}}},{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),UnionSchema=function(e){function t(e,n){if(classCallCheck(this,t),!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n))}return inherits(t,e),createClass(t,[{key:"normalize",value:function(e,t,n,r,i){return this.normalizeValue(e,t,n,r,i)}}]),t}(PolymorphicSchema),ValuesSchema=function(e){function t(){return classCallCheck(this,t),possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return inherits(t,e),createClass(t,[{key:"normalize",value:function(e,t,n,r,i){var o=this;return Object.keys(e).reduce(function(t,n,a){var u=e[n];return void 0!==u&&null!==u?_extends({},t,defineProperty({},n,o.normalizeValue(u,e,n,r,i))):t},{})}}]),t}(PolymorphicSchema),validateSchema=function(e){var t=Array.isArray(e);if(t&&e.length>1)throw new Error("Expected schema definition to be a single schema, but found "+e.length+".");return e[0]},normalize$2=function(e,t,n,r,i,o){e=validateSchema(e);var a=Array.isArray(t)?t:Object.values(t);return a.map(function(t,a){return i(t,n,r,e,o)})},ArraySchema=function(e){function t(){return classCallCheck(this,t),possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return inherits(t,e),createClass(t,[{key:"normalize",value:function(e,t,n,r,i){var o=this,a=Array.isArray(e)?e:Object.values(e);return a.map(function(e,a){return o.normalizeValue(e,t,n,r,i)}).filter(function(e){return void 0!==e&&null!==e})}}]),t}(PolymorphicSchema),_normalize=function(e,t,n,r,i,o){var a=_extends({},t);return Object.keys(e).forEach(function(n){var r=e[n],u=i(t[n],t,n,r,o);void 0===u||null===u?delete a[n]:a[n]=u}),a},ObjectSchema=function(){function e(t){classCallCheck(this,e),this.define(t)}return createClass(e,[{key:"define",value:function(e){this.schema=Object.keys(e).reduce(function(t,n){var r=e[n];return _extends({},t,defineProperty({},n,r))},this.schema||{})}},{key:"normalize",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return _normalize.apply(void 0,[this.schema].concat(t))}}]),e}(),visit=function e(t,n,r,i,o){if("object"!==("undefined"==typeof t?"undefined":_typeof(t))||!t)return t;if("object"===("undefined"==typeof i?"undefined":_typeof(i))&&(!i.normalize||"function"!=typeof i.normalize)){var a=_normalize;return Array.isArray(i)&&(a=normalize$2),a(i,t,n,r,e,o)}return i.normalize(t,n,r,e,o)},addEntities=function(e){return function(t,n,r,i,o){var a=t.getKey(r,i,o),u=t.getId(r,i,o);a in e||(e[a]={});var c=e[a][u];c?e[a][u]=t.merge(c,n):e[a][u]=n}},schema={Array:ArraySchema,Entity:EntitySchema,Object:ObjectSchema,Union:UnionSchema,Values:ValuesSchema},normalize$1=function(e,t){if(!e||"object"!==("undefined"==typeof e?"undefined":_typeof(e)))throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+("undefined"==typeof e?"undefined":_typeof(e))+'".');var n={},r=addEntities(n),i=visit(e,e,null,t,r);return{entities:n,result:i}};exports.schema=schema,exports.normalize=normalize$1;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),defineProperty=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},get$1=function e(t,n,r){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(void 0===i){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,r)}if("value"in i)return i.value;var a=i.get;if(void 0!==a)return a.call(r)},inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},set=function e(t,n,r,i){var o=Object.getOwnPropertyDescriptor(t,n);if(void 0===o){var a=Object.getPrototypeOf(t);null!==a&&e(a,n,r,i)}else if("value"in o&&o.writable)o.value=r;else{var c=o.set;void 0!==c&&c.call(i,r)}return r},EntitySchema=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(classCallCheck(this,e),!t||"string"!=typeof t)throw new Error("Expected a string key for Entity, but found "+t+".");var i=r.idAttribute,o=void 0===i?"id":i,a=r.mergeStrategy,c=void 0===a?function(e,t){return _extends({},e,t)}:a,u=r.processStrategy,s=void 0===u?function(e){return _extends({},e)}:u;this._key=t,this._getId="function"==typeof o?o:function(e){return e[o]},this._mergeStrategy=c,this._processStrategy=s,this.define(n)}return createClass(e,[{key:"define",value:function(e){this.schema=Object.keys(e).reduce(function(t,n){var r=e[n];return _extends({},t,defineProperty({},n,r))},this.schema||{})}},{key:"getId",value:function(e,t,n){return this._getId(e,t,n)}},{key:"merge",value:function(e,t){return this._mergeStrategy(e,t)}},{key:"normalize",value:function(e,t,n,r,i){var o=this,a=this._processStrategy(e,t,n);return Object.keys(this.schema).forEach(function(e){if(a.hasOwnProperty(e)&&"object"===_typeof(a[e])){var t=o.schema[e];a[e]=r(a[e],a,e,t,i)}}),i(this,a,e,t,n),this.getId(e,t,n)}},{key:"key",get:function(){return this._key}}]),e}(),PolymorphicSchema=function(){function e(t,n){classCallCheck(this,e),n&&(this._schemaAttribute="string"==typeof n?function(e){return e[n]}:n),this.define(t)}return createClass(e,[{key:"define",value:function(e){this.schema=e}},{key:"getSchemaAttribute",value:function(e,t,n){return!this.isSingleSchema&&this._schemaAttribute(e,t,n)}},{key:"inferSchema",value:function(e,t,n){if(this.isSingleSchema)return this.schema;var r=this.getSchemaAttribute(e,t,n),i=this.schema[r];if(!i)throw new Error('No schema found for attribute "'+r+'".');return i}},{key:"normalizeValue",value:function(e,t,n,r,i){var o=this.inferSchema(e,t,n),a=r(e,t,n,o,i);return this.isSingleSchema||void 0===a||null===a?a:{id:a,schema:this.getSchemaAttribute(e,t,n)}}},{key:"isSingleSchema",get:function(){return!this._schemaAttribute}}]),e}(),UnionSchema=function(e){function t(e,n){if(classCallCheck(this,t),!n)throw new Error('Expected option "schemaAttribute" not found on UnionSchema.');return possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n))}return inherits(t,e),createClass(t,[{key:"normalize",value:function(e,t,n,r,i){return this.normalizeValue(e,t,n,r,i)}}]),t}(PolymorphicSchema),ValuesSchema=function(e){function t(){return classCallCheck(this,t),possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return inherits(t,e),createClass(t,[{key:"normalize",value:function(e,t,n,r,i){var o=this;return Object.keys(e).reduce(function(t,n,a){var c=e[n];return void 0!==c&&null!==c?_extends({},t,defineProperty({},n,o.normalizeValue(c,e,n,r,i))):t},{})}}]),t}(PolymorphicSchema),validateSchema=function(e){var t=Array.isArray(e);if(t&&e.length>1)throw new Error("Expected schema definition to be a single schema, but found "+e.length+".");return e[0]},normalize$2=function(e,t,n,r,i,o){e=validateSchema(e);var a=Array.isArray(t)?t:Object.values(t);return a.map(function(t,a){return i(t,n,r,e,o)})},ArraySchema=function(e){function t(){return classCallCheck(this,t),possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return inherits(t,e),createClass(t,[{key:"normalize",value:function(e,t,n,r,i){var o=this,a=Array.isArray(e)?e:Object.values(e);return a.map(function(e,a){return o.normalizeValue(e,t,n,r,i)}).filter(function(e){return void 0!==e&&null!==e})}}]),t}(PolymorphicSchema),_normalize=function(e,t,n,r,i,o){var a=_extends({},t);return Object.keys(e).forEach(function(n){var r=e[n],c=i(t[n],t,n,r,o);void 0===c||null===c?delete a[n]:a[n]=c}),a},ObjectSchema=function(){function e(t){classCallCheck(this,e),this.define(t)}return createClass(e,[{key:"define",value:function(e){this.schema=Object.keys(e).reduce(function(t,n){var r=e[n];return _extends({},t,defineProperty({},n,r))},this.schema||{})}},{key:"normalize",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return _normalize.apply(void 0,[this.schema].concat(t))}}]),e}(),visit=function e(t,n,r,i,o){if("object"!==("undefined"==typeof t?"undefined":_typeof(t))||!t)return t;if("object"===("undefined"==typeof i?"undefined":_typeof(i))&&(!i.normalize||"function"!=typeof i.normalize)){var a=_normalize;return Array.isArray(i)&&(a=normalize$2),a(i,t,n,r,e,o)}return i.normalize(t,n,r,e,o)},addEntities=function(e){return function(t,n,r,i,o){var a=t.key,c=t.getId(r,i,o);a in e||(e[a]={});var u=e[a][c];u?e[a][c]=t.merge(u,n):e[a][c]=n}},schema={Array:ArraySchema,Entity:EntitySchema,Object:ObjectSchema,Union:UnionSchema,Values:ValuesSchema},normalize$1=function(e,t){if(!e||"object"!==("undefined"==typeof e?"undefined":_typeof(e)))throw new Error('Unexpected input given to normalize. Expected type to be "object", found "'+("undefined"==typeof e?"undefined":_typeof(e))+'".');var n={},r=addEntities(n),i=visit(e,e,null,t,r);return{entities:n,result:i}};exports.schema=schema,exports.normalize=normalize$1;
{
"name": "normalizr",
"version": "3.0.0-beta",
"version": "3.0.0-beta.2",
"description": "Normalizes JSON according to schema for Redux and Flux applications",

@@ -22,2 +22,3 @@ "bugs": {

"dist/",
"index.d.ts",
"LICENSE",

@@ -27,2 +28,3 @@ "README.md"

"main": "dist/index.js",
"typings": "index.d.ts",
"scripts": {

@@ -61,4 +63,6 @@ "build": "npm run clean && mkdirp dist && npm-run-all --parallel build:development build:production",

"rollup-plugin-filesize": "^1.0.1",
"rollup-plugin-uglify": "^1.0.1"
"rollup-plugin-uglify": "^1.0.1",
"typescript": "^2.1.4",
"typescript-definition-tester": "0.0.5"
}
}

@@ -1,2 +0,2 @@

# normalizr [![build status](https://img.shields.io/travis/paularmstrong/normalizr/normalizr3.svg?style=flat-square)](https://travis-ci.org/paularmstrong/normalizr) [![Coverage Status](https://img.shields.io/coveralls/paularmstrong/normalizr/normalizr3.svg?style=flat-square)](https://coveralls.io/github/paularmstrong/normalizr?branch=normalizr3) [![npm version](https://img.shields.io/npm/v/normalizr.svg?style=flat-square)](https://www.npmjs.com/package/normalizr) [![npm downloads](https://img.shields.io/npm/dm/normalizr.svg?style=flat-square)](https://www.npmjs.com/package/normalizr)
# normalizr [![build status](https://img.shields.io/travis/paularmstrong/normalizr/master.svg?style=flat-square)](https://travis-ci.org/paularmstrong/normalizr) [![Coverage Status](https://img.shields.io/coveralls/paularmstrong/normalizr/master.svg?style=flat-square)](https://coveralls.io/github/paularmstrong/normalizr?branch=master) [![npm version](https://img.shields.io/npm/v/normalizr.svg?style=flat-square)](https://www.npmjs.com/package/normalizr) [![npm downloads](https://img.shields.io/npm/dm/normalizr.svg?style=flat-square)](https://www.npmjs.com/package/normalizr)

@@ -3,0 +3,0 @@ ## Motivation

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