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

morphism

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

morphism - npm Package Compare versions

Comparing version 1.6.1 to 1.7.0

2

dist/helpers.d.ts
export declare const aggregator: (paths: any, object: any) => any;
export declare function assignInWith(target: any, source: any, customizer?: (targetValue: any, sourceValue: any) => any): any;
export declare function isUndefined(value: any): boolean;
export declare function isObject(value: any): boolean;
export declare function isObject(value: any): value is object;
export declare function isString(value: any): value is string;

@@ -6,0 +6,0 @@ export declare function isFunction(value: any): value is (...args: any[]) => any;

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

export declare function isActionSelector(value: any): value is ActionSelector;
/**
* A Function invoked per iteration
* @param {} iteratee The current element to transform
* @param source The source input to transform
* @param target The current element transformed
* @example
* ```typescript
*
* const source = {
* foo: {
* bar: 'bar'
* }
* };
* let schema = {
* bar: iteratee => {
* // Apply a function over the source propery
* return iteratee.foo.bar;
* }
* };
*
* morphism(schema, source);
* //=> { bar: 'bar' }
* ```
*
*/
export interface ActionFunction<D, S> {
(iteratee: S, source: S[], target: D): any;
}
/**
* A String path that indicates where to find the property in the source input

@@ -24,31 +53,3 @@ *

*/
export declare type ActionString = string;
export declare type ActionFunction = {
/**
* A Function invoked per iteration
* @param {} iteratee The current element to transform
* @param source The source input to transform
* @param target The current element transformed
* @example
* ```typescript
*
* const source = {
* foo: {
* bar: 'bar'
* }
* };
* let schema = {
* bar: iteratee => {
* // Apply a function over the source propery
* return iteratee.foo.bar;
* }
* };
*
* morphism(schema, source);
* //=> { bar: 'bar' }
* ```
*
*/
(iteratee: any, source: any | any[], target: any): any;
};
export declare type ActionString<T> = keyof T;
/**

@@ -100,7 +101,38 @@ * An Array of String that allows to perform a function over source property

};
export declare type StrictSchema<Target> = {
[destinationProperty in keyof Target]: ActionString | ActionFunction | ActionAggregator | ActionSelector;
/**
* A structure-preserving object from a source data towards a target data.
*
* The keys of the schema match the desired destination structure.
* Each value corresponds to an Action applied by Morphism when iterating over the input data
* @example
* ```typescript
*
* const input = {
* foo: {
* baz: 'value1'
* }
* };
*
* const schema: Schema = {
* bar: 'foo', // ActionString
* qux: ['foo', 'foo.baz'], // ActionAggregator
* quux: (iteratee, source, destination) => { // ActionFunction
* return iteratee.foo;
* },
* corge: { // ActionSelector
* path: 'foo.baz',
* fn: (propertyValue, source) => {
* return propertyValue;
* }
* }
* };
*
* morphism(schema, input);
* ```
*/
export declare type StrictSchema<Target = {}, Source = any> = {
[destinationProperty in keyof Target]: ActionString<Source> | ActionFunction<Target, Source> | ActionAggregator | ActionSelector;
};
export declare type Schema<Target> = {
[destinationProperty in keyof Target]?: ActionString | ActionFunction | ActionAggregator | ActionSelector;
export declare type Schema<Target = {}, Source = any> = {
[destinationProperty in keyof Target]?: ActionString<Source> | ActionFunction<Target, Source> | ActionAggregator | ActionSelector;
};

@@ -110,3 +142,3 @@ interface Constructable<T> {

}
interface Mapper<Target> {
export interface Mapper<Target> {
<Source>(source: Source[]): Target[];

@@ -137,10 +169,7 @@ <Source>(source: Source): Target;

*/
export declare function morphism<TSchema extends Schema<any>>(schema: TSchema, items: any[]): {
export declare function morphism<TSchema extends Schema<{}, Source>, Source>(schema: TSchema, items: Source): Source extends any[] ? {
[P in keyof TSchema]: any;
}[];
export declare function morphism<TSchema extends Schema<any>>(schema: TSchema, items: any): {
}[] : {
[P in keyof TSchema]: any;
};
export declare function morphism<Target>(schema: Schema<Target>, items: any[]): Target[];
export declare function morphism<Target>(schema: Schema<Target>, items: any): Target;
export declare function morphism<TSchema extends Schema<any>>(schema: TSchema): Mapper<{

@@ -150,4 +179,2 @@ [P in keyof TSchema]: any;

export declare function morphism<Target>(schema: Schema<Target>): Mapper<Target>;
export declare function morphism(schema: Schema<any>, items: null): undefined;
export declare function morphism(schema: null, items: {}): undefined;
export declare function morphism<Target, Source>(schema: Schema<Target>, items: null, type: Constructable<Target>): Mapper<Target>;

@@ -154,0 +181,0 @@ export declare function morphism<Target, Source>(schema: Schema<Target>, items: Source[], type: Constructable<Target>): Target[];

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

module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return r[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var i in r)t.d(n,i,function(e){return r[e]}.bind(null,i));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){"use strict";var n=this&&this.__read||function(r,e){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var n,i,o=t.call(r),u=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)u.push(n.value)}catch(r){i={error:r}}finally{try{n&&!n.done&&(t=o.return)&&t.call(o)}finally{if(i)throw i.error}}return u};Object.defineProperty(e,"__esModule",{value:!0});var i=t(1);function o(r,e,t,o){return Object.entries(e).map(function(e){var u,a,c,f,s=n(e,2),p=s[0],l=s[1];if(i.isString(l))return(u={})[p]=i.get(r,l),u;if(i.isFunction(l))return(a={})[p]=l.call(void 0,r,t,o),a;if(Array.isArray(l))return(c={})[p]=i.aggregator(l,r),c;if(i.isObject(l)){var h=void 0;try{var y=void 0;Array.isArray(l.path)?y=i.aggregator(l.path,r):i.isString(l.path)&&(y=i.get(r,l.path)),h=l.fn.call(void 0,y,r,t,o)}catch(r){throw r.message="Unable to set target property ["+p+"].\n \n An error occured when applying ["+l.fn.name+"] on property ["+l.path+"]\n \n Internal error: "+r.message,r}return(f={})[p]=h,f}}).reduce(function(r,e){return i.assignInWith(r,e,function(r,e){return i.isUndefined(e)?i.isUndefined(r)?void 0:r:e})},o)}function u(r,e){return function(t){if(!t)return t;if(Array.isArray(t))return t.map(function(n){if(e){var i=new e;return o(n,r,t,i)}return o(n,r,t,{})});var n=t;if(e){var i=new e;return o(n,r,[n],i)}return o(n,r,[n],{})}}function a(r,e){var t=Object.keys(new r),n=i.zipObject(t,t);return Object.assign(n,e)}function c(r,e,t){if(void 0===e&&void 0===t)return u(r);if(r&&e&&t)return u(a(t,r),t)(e);if(r&&e)return u(r)(e);if(t&&e)return u(a(t,r),t)(e);if(t){var n=a(t,r);return function(r){return u(n,t)(r)}}}e.morphism=c;var f=function(){function r(r){this._registry=null,this._registry=r||{cache:new Map}}return r.prototype.register=function(r,e){if(!r&&!e)throw new Error("type paramater is required when register a mapping");if(this.exists(r))throw new Error("A mapper for "+r.name+" has already been registered");var t=c(e,null,r);return this._registry.cache.set(r,t),t},r.prototype.map=function(r,e){if(!this.exists(r)){var t=this.register(r);if(void 0===e)return t}return this.getMapper(r)(e)},r.prototype.getMapper=function(r){return this._registry.cache.get(r)},r.prototype.setMapper=function(r,e){if(e){if(this.exists(r)){var t=c(e,null,r);return this._registry.cache.set(r,t),t}throw new Error("The type "+r.name+" is not registered. Register it using `Mophism.register("+r.name+", schema)`")}throw new Error("The schema must be an Object. Found "+e)},r.prototype.deleteMapper=function(r){return this._registry.cache.delete(r)},r.prototype.exists=function(r){return this._registry.cache.has(r)},Object.defineProperty(r.prototype,"mappers",{get:function(){return this._registry.cache},enumerable:!0,configurable:!0}),r}();function s(r){return function(e,t,n){var i=n.value;return"function"==typeof i&&(n.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=i.apply(this,e);return function(r){if(Promise&&Promise.resolve)return Promise.resolve(r)==r;throw"Promise not supported in your environment"}(n)?Promise.resolve(n).then(function(e){return r(e)}):r(n)}),n}}e.MorphismRegistry=f,e.morph=function(r,e){return s(u(r,e))},e.toJSObject=function(r){return s(u(r))},e.toClassObject=function(r,e){return s(u(r,e))};var p=new f,l=c;l.register=function(r,e){return p.register(r,e)},l.map=function(r,e){return p.map(r,e)},l.getMapper=function(r){return p.getMapper(r)},l.setMapper=function(r,e){return p.setMapper(r,e)},l.deleteMapper=function(r){return p.deleteMapper(r)},l.mappers=p.mappers;var h=l;e.default=h},function(r,e,t){"use strict";var n=this&&this.__assign||Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i]);return r},i=this&&this.__read||function(r,e){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var n,i,o=t.call(r),u=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)u.push(n.value)}catch(r){i={error:r}}finally{try{n&&!n.done&&(t=o.return)&&t.call(o)}finally{if(i)throw i.error}}return u};function o(r){var e=typeof r;return null!=r&&("object"===e||"function"===e)}function u(r,e,t){var i,o=(e=(e=e.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split("."),u=o.pop(),a=o.reduceRight(function(r,e){var t;return(t={})[e]=r,t},((i={})[u]=t,i));return n({},r,a)}function a(r,e){for(var t=(e=(e=e.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split("."),n=0,i=t.length;n<i;++n){var u=t[n];if(!(o(r)&&u in r))return;r=r[u]}return r}Object.defineProperty(e,"__esModule",{value:!0}),e.aggregator=function(r,e){return r.reduce(function(r,t){return u(r,t,a(e,t))},{})},e.assignInWith=function(r,e,t){return Object.entries(e).forEach(function(e){var n=i(e,2),o=n[0],u=n[1];r[o]=t?t(r[o],u):u}),r},e.isUndefined=function(r){return void 0===r},e.isObject=o,e.isString=function(r){return"string"==typeof r||r instanceof String},e.isFunction=function(r){return"function"==typeof r},e.set=u,e.get=a,e.zipObject=function(r,e){return r.reduce(function(r,t,i){var o;return n({},r,((o={})[t]=e[i],o))},{})}}]);
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return r[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var i in r)t.d(n,i,function(e){return r[e]}.bind(null,i));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){"use strict";var n=this&&this.__read||function(r,e){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var n,i,o=t.call(r),u=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)u.push(n.value)}catch(r){i={error:r}}finally{try{n&&!n.done&&(t=o.return)&&t.call(o)}finally{if(i)throw i.error}}return u};Object.defineProperty(e,"__esModule",{value:!0});var i=t(1);function o(r){return i.isObject(r)}function u(r,e,t,u){return Object.entries(e).map(function(e){var a,c,f,s,p=n(e,2),l=p[0],h=p[1];if(i.isString(h))return(a={})[l]=i.get(r,h),a;if(i.isFunction(h))return(c={})[l]=h.call(void 0,r,t,u),c;if(Array.isArray(h))return(f={})[l]=i.aggregator(h,r),f;if(o(h)){var y=void 0;try{var g=void 0;Array.isArray(h.path)?g=i.aggregator(h.path,r):i.isString(h.path)&&(g=i.get(r,h.path)),y=h.fn.call(void 0,g,r,t,u)}catch(r){throw r.message="Unable to set target property ["+l+"].\n \n An error occured when applying ["+h.fn.name+"] on property ["+h.path+"]\n \n Internal error: "+r.message,r}return(s={})[l]=y,s}}).reduce(function(r,e){return i.assignInWith(r,e,function(r,e){return i.isUndefined(e)?i.isUndefined(r)?void 0:r:e})},u)}function a(r,e){return function(t){if(!t)return t;if(Array.isArray(t))return t.map(function(n){if(e){var i=new e;return u(n,r,t,i)}return u(n,r,t,{})});var n=t;if(e){var i=new e;return u(n,r,[n],i)}return u(n,r,[n],{})}}function c(r,e){var t=Object.keys(new r),n=i.zipObject(t,t);return Object.assign(n,e)}function f(r,e,t){if(void 0===e&&void 0===t)return a(r);if(r&&e&&t)return a(c(t,r),t)(e);if(r&&e)return a(r)(e);if(t&&e)return a(c(t,r),t)(e);if(t){var n=c(t,r);return function(r){return a(n,t)(r)}}}e.isActionSelector=o,e.morphism=f;var s=function(){function r(r){this._registry=null,this._registry=r||{cache:new Map}}return r.prototype.register=function(r,e){if(!r&&!e)throw new Error("type paramater is required when register a mapping");if(this.exists(r))throw new Error("A mapper for "+r.name+" has already been registered");var t=f(e,null,r);return this._registry.cache.set(r,t),t},r.prototype.map=function(r,e){if(!this.exists(r)){var t=this.register(r);if(void 0===e)return t}return this.getMapper(r)(e)},r.prototype.getMapper=function(r){return this._registry.cache.get(r)},r.prototype.setMapper=function(r,e){if(e){if(this.exists(r)){var t=f(e,null,r);return this._registry.cache.set(r,t),t}throw new Error("The type "+r.name+" is not registered. Register it using `Mophism.register("+r.name+", schema)`")}throw new Error("The schema must be an Object. Found "+e)},r.prototype.deleteMapper=function(r){return this._registry.cache.delete(r)},r.prototype.exists=function(r){return this._registry.cache.has(r)},Object.defineProperty(r.prototype,"mappers",{get:function(){return this._registry.cache},enumerable:!0,configurable:!0}),r}();function p(r){return function(e,t,n){var i=n.value;return"function"==typeof i&&(n.value=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=i.apply(this,e);return function(r){if(Promise&&Promise.resolve)return Promise.resolve(r)==r;throw"Promise not supported in your environment"}(n)?Promise.resolve(n).then(function(e){return r(e)}):r(n)}),n}}e.MorphismRegistry=s,e.morph=function(r,e){return p(a(r,e))},e.toJSObject=function(r){return p(a(r))},e.toClassObject=function(r,e){return p(a(r,e))};var l=new s,h=f;h.register=function(r,e){return l.register(r,e)},h.map=function(r,e){return l.map(r,e)},h.getMapper=function(r){return l.getMapper(r)},h.setMapper=function(r,e){return l.setMapper(r,e)},h.deleteMapper=function(r){return l.deleteMapper(r)},h.mappers=l.mappers;var y=h;e.default=y},function(r,e,t){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i]);return r}).apply(this,arguments)},i=this&&this.__read||function(r,e){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var n,i,o=t.call(r),u=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)u.push(n.value)}catch(r){i={error:r}}finally{try{n&&!n.done&&(t=o.return)&&t.call(o)}finally{if(i)throw i.error}}return u};function o(r){var e=typeof r;return null!=r&&("object"===e||"function"===e)}function u(r,e,t){var i,o=(e=(e=e.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split("."),u=o.pop(),a=o.reduceRight(function(r,e){var t;return(t={})[e]=r,t},((i={})[u]=t,i));return n({},r,a)}function a(r,e){for(var t=(e=(e=e.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split("."),n=0,i=t.length;n<i;++n){var u=t[n];if(!(o(r)&&u in r))return;r=r[u]}return r}Object.defineProperty(e,"__esModule",{value:!0}),e.aggregator=function(r,e){return r.reduce(function(r,t){return u(r,t,a(e,t))},{})},e.assignInWith=function(r,e,t){return Object.entries(e).forEach(function(e){var n=i(e,2),o=n[0],u=n[1];r[o]=t?t(r[o],u):u}),r},e.isUndefined=function(r){return void 0===r},e.isObject=o,e.isString=function(r){return"string"==typeof r||r instanceof String},e.isFunction=function(r){return"function"==typeof r},e.set=u,e.get=a,e.zipObject=function(r,e){return r.reduce(function(r,t,i){var o;return n({},r,((o={})[t]=e[i],o))},{})}}]);
{
"name": "morphism",
"version": "1.6.1",
"version": "1.7.0",
"description": "Library to transform any Object / JSON to JavaScript Object Literals, and ES6 Class Objects. Help you scale your data processing",

@@ -39,18 +39,18 @@ "homepage": "https://github.com/nobrainr/morphism",

"devDependencies": {
"@types/jasmine": "^2.8.8",
"@types/jasmine": "^3.3.5",
"awesome-typescript-loader": "^5.2.0",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"expect": "^22.4.3",
"expect": "^23.6.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine": "^3.1.0",
"jasmine-core": "^3.1.0",
"karma": "^2.0.5",
"karma": "^3.1.4",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^1.4.3",
"karma-jasmine": "^1.1.2",
"karma-coverage-istanbul-reporter": "^2.0.4",
"karma-jasmine": "^2.0.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "^3.0.0",
"now": "^11.4.1",
"now": "^13.0.3",
"rimraf": "^2.6.1",

@@ -64,7 +64,7 @@ "semantic-release": "^15.8.1",

"typedoc-plugin-internal-external": "^1.0.10",
"typescript": "^2.9.2",
"typescript": "^3.2.2",
"webpack": "^4.16.3",
"webpack-cli": "^2.1.5",
"webpack-cli": "^3.2.1",
"webpack-dashboard": "^2.0.0",
"webpack-dev-server": "3.1.3"
"webpack-dev-server": "3.1.14"
},

@@ -71,0 +71,0 @@ "eslintConfig": {

@@ -47,7 +47,7 @@ # Morphism

- [Registry API](#registry-api)
- [Register](#register)
- [Map](#map)
- [Get or Set an existing mapper configuration](#get-or-set-an-existing-mapper-configuration)
- [Delete a registered mapper](#delete-a-registered-mapper)
- [List registered mappers](#list-registered-mappers)
- [Register](#register)
- [Map](#map)
- [Get or Set an existing mapper configuration](#get-or-set-an-existing-mapper-configuration)
- [Delete a registered mapper](#delete-a-registered-mapper)
- [List registered mappers](#list-registered-mappers)
- [Contribution](#contribution)

@@ -241,3 +241,3 @@ - [Similar Projects](#similar-projects)

#### - `toJsObject` Decorator
#### `toJsObject` Decorator

@@ -289,3 +289,3 @@ ```ts

#### - `toClassObject` Decorator
#### `toClassObject` Decorator

@@ -538,3 +538,4 @@ ```ts

- [`JavaScript AutoMapper`](https://github.com/loedeman/AutoMapper)
- [`object-mapper`](https://www.npmjs.com/package/object-mapper)
- [`autoMapper-ts`](https://www.npmjs.com/package/automapper-ts)
- [`C# AutoMapper`](https://github.com/AutoMapper/AutoMapper)

@@ -541,0 +542,0 @@ - [`node-data-transform`](https://github.com/bozzltron/node-json-transform)

Sorry, the diff of this file is not supported yet

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