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

props-model

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

props-model - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

2

dist/index.js

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

"use strict";var _propsModel=_interopRequireDefault(require("./lib/props-model"));Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var _default=_propsModel.default;exports.default=_default;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.PropsModel=void 0;var _propsModel=require("./lib/props-model"),PropsModel=_propsModel.PropsModel;exports.PropsModel=PropsModel;var _default=PropsModel;exports.default=_default;

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;function _toArray(a){return _arrayWithHoles(a)||_iterableToArray(a)||_nonIterableRest()}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function _arrayWithHoles(a){if(Array.isArray(a))return a}function PropsModel(a){this._eventEmitter=a,this._props={}}var _default=PropsModel;exports.default=_default;function NOOP(){}function defaultDidChange(a,b){return a!==b}PropsModel.prototype._firePropChangeEvent=function(a,b,c){this._eventEmitter.emit("".concat(a,"-changed"),a,b,c)},PropsModel.prototype.defineProp=function(a,b){var c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:NOOP,d=3<arguments.length&&void 0!==arguments[3]?arguments[3]:defaultDidChange;if(this._props[a])throw new Error("Property already defined: ".concat(a));return this._props[a]={value:b,derived:!1,valueValidator:c,didChange:d},d(b,void 0)&&this._firePropChangeEvent(a,b,void 0),this},PropsModel.prototype.defineDerivedProp=function(a){var b=this,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],d=2<arguments.length?arguments[2]:void 0,e=3<arguments.length?arguments[3]:void 0,f=4<arguments.length&&void 0!==arguments[4]?arguments[4]:defaultDidChange;if(this._props[a])throw new Error("Property already defined: ".concat(a));var g=this.createUtilizer(c,d),h="undefined"==typeof e?g():e;return this._props[a]={value:h,derived:!0,valueValidator:function a(){},didChange:f},this._onAny(function(){},c,function(){b.set(a,g())}),f(h,void 0)&&this._firePropChangeEvent(a,h,void 0),this},PropsModel.prototype._set=function(a){for(var b=this,c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];if(1===d.length){var h=[];Object.keys(d[0]).forEach(function(a){if(!b._props[a])throw new Error("No such property '".concat(a,"'"))}),Object.keys(d[0]).forEach(a),Object.entries(d[0]).forEach(function(a){var c=_slicedToArray(a,2),d=c[0],e=c[1];b._props[d].valueValidator(e)}),Object.entries(d[0]).forEach(function(a){var c=_slicedToArray(a,2),d=c[0],e=c[1],f=b._props[d].value;b._props[d].value=e,b._props[d].didChange(e,f)&&h.push([d,e,f])}),h.forEach(function(a){return b._firePropChangeEvent.apply(b,_toConsumableArray(a))})}else{var f=d[0],g=d[1];if(!this._props[f])throw new Error("No such property '".concat(f,"'"));a(f),this._props[f].valueValidator(g);var i=this._props[f].value;this._props[f].value=g,this._props[f].didChange(g,i)&&this._firePropChangeEvent(f,g,i)}},PropsModel.prototype._get=function(a,b){if(a(b),!this._props[b])throw new Error("No such property '".concat(b,"'"));return this._props[b].value},PropsModel.prototype._toJSON=function(a){return Object.entries(this._props).filter(function(b){var c=_slicedToArray(b,1),d=c[0];return a(d)}).reduce(function(a,b){var c=_slicedToArray(b,2),d=c[0],e=c[1].value;return a[d]=e,a},{})};function createAccessorNames(a){for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];return c.map(function(b){return"".concat(b).concat(a.replace(/^./,function(a){return a.toUpperCase()}))})}PropsModel.prototype._installAccessors=function(a,b,c,d){for(var e=this,f=Object.keys(d),g=0;g<f.length;g++){var h=f[g],i=d[h];if(!this._props[h])throw new Error("Cannot create accessors for non-existant property '".concat(h,"'"));switch(i.toLowerCase()){case"readonly":a(h);break;case"readwrite":a(h),b(h);break;case"none":break;default:throw new Error("Unknown access type '".concat(i,"' specified for property '").concat(h,"'"));}}for(var j=Object.keys(d),k=function(){var a,b=j[l],f=d[b];switch(f.toLowerCase()){case"readonly":var g=createAccessorNames(b,"get"),h=_slicedToArray(g,1),i=h[0],k=_defineProperty({},i,function(){return e._props[b].value})[i];c[i]=k;break;case"readwrite":var m=createAccessorNames(b,"get","set"),n=_slicedToArray(m,2),o=n[0],p=n[1],q=(a={},_defineProperty(a,o,function(){return e._props[b].value}),_defineProperty(a,p,function(a){e._set(function(){},b,a)}),a);c[o]=q[o],c[p]=q[p];break;default:}},l=0;l<j.length;l++)k()},PropsModel.prototype._createUtilizer=function(a,b,c){var d=this,e=_toArray(b),f=e.slice(0);return f.forEach(a),f.forEach(function(a){if(!d._props[a])throw new Error("Cannot create utilizer of unknown property '".concat(a,"'"))}),function(){for(var a=arguments.length,b=Array(a),e=0;e<a;e++)b[e]=arguments[e];return c.apply(void 0,_toConsumableArray(f.map(function(a){return d._props[a].value})).concat(b))}},PropsModel.prototype._onAny=function(a,b,c){var d=_toArray(b),e=d.slice(0);e.forEach(a);for(var f=0;f<e.length;f++)this._eventEmitter.on("".concat(e[f],"-changed"),c)},PropsModel.prototype._createChangeHandler=function(a,b,c){var d=_toArray(b),e=d.slice(0),f=this._createUtilizer(a,e,c);return this._onAny(function(){},e,function(){return f()}),f},PropsModel.prototype.createUtilizer=function(a,b){return this._createUtilizer(function(){},a,b)},PropsModel.prototype.onAny=function(a,b){return this._onAny(function(){},a,b)},PropsModel.prototype.createChangeHandler=function(a,b){return this._createChangeHandler(function(){},a,b)},PropsModel.prototype.set=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return this._set.apply(this,[function(){}].concat(b))},PropsModel.prototype.get=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return this._get.apply(this,[function(){}].concat(b))},PropsModel.prototype.toJSON=function(){return this._toJSON(function(){return!0})},PropsModel.prototype.installAccessors=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return this._installAccessors.apply(this,[function(){},function(){}].concat(b))};function propertyCheckerToValidator(a){return function(b){var c=a(b);if(c instanceof Error)throw c;else if(!c)throw new Error("Requested access to property '".concat(b,"' is not allowed"))}}PropsModel.prototype.createApi=function(a){var b=this,c=1<arguments.length&&arguments[1]!==void 0?arguments[1]:propertyCheckerToValidator(a),d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:c;return{get:function f(){for(var a=arguments.length,d=Array(a),e=0;e<a;e++)d[e]=arguments[e];return b._get.apply(b,[c].concat(d))},set:function f(){for(var a=arguments.length,c=Array(a),e=0;e<a;e++)c[e]=arguments[e];return b._set.apply(b,[d].concat(c))},createUtilizer:function f(){for(var a=arguments.length,d=Array(a),e=0;e<a;e++)d[e]=arguments[e];return b._createUtilizer.apply(b,[c].concat(d))},createChangeHandler:function f(){for(var a=arguments.length,d=Array(a),e=0;e<a;e++)d[e]=arguments[e];return b._createChangeHandler.apply(b,[c].concat(d))},installAccessors:function g(){for(var a=arguments.length,e=Array(a),f=0;f<a;f++)e[f]=arguments[f];return b._installAccessors.apply(b,[c,d].concat(e))},toJSON:function c(){return b._toJSON(a)}}};function propNameIsPublic(a){return!a.startsWith("_")}function assertPropNameIsPublic(a){if(!propNameIsPublic(a))throw new Error("Property is not publicly accessible: ".concat(a))}function createStandardWriteValidator(a){return function(b){if(a._props[b].derived)throw new Error("Write access to ".concat(b," is not allowed because the property is a derived property."))}}PropsModel.prototype.getStandardPublicApi=function(){var a=createStandardWriteValidator(this);return this.createApi(propNameIsPublic,assertPropNameIsPublic,function(b){assertPropNameIsPublic(b),a(b)})},PropsModel.prototype.getStandardPrivateApi=function(){return this.createApi(function(){return!0},function(){},createStandardWriteValidator(this))};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropsModel=PropsModel;function _toArray(a){return _arrayWithHoles(a)||_iterableToArray(a)||_nonIterableRest()}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function _arrayWithHoles(a){if(Array.isArray(a))return a}function PropsModel(a){this._eventEmitter=a,this._props={}}function NOOP(){}function defaultDidChange(a,b){return a!==b}PropsModel.prototype._firePropChangeEvent=function(a,b,c){this._eventEmitter.emit("".concat(a,"-changed"),a,b,c)},PropsModel.prototype.defineProp=function(a,b){var c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:NOOP,d=3<arguments.length&&void 0!==arguments[3]?arguments[3]:defaultDidChange;if(this._props[a])throw new Error("Property already defined: ".concat(a));return this._props[a]={value:b,derived:!1,valueValidator:c,didChange:d},d(b,void 0)&&this._firePropChangeEvent(a,b,void 0),this},PropsModel.prototype.defineDerivedProp=function(a){var b=this,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],d=2<arguments.length?arguments[2]:void 0,e=3<arguments.length?arguments[3]:void 0,f=4<arguments.length&&void 0!==arguments[4]?arguments[4]:defaultDidChange;if(this._props[a])throw new Error("Property already defined: ".concat(a));var g=this.createUtilizer(c,d),h="undefined"==typeof e?g():e;return this._props[a]={value:h,derived:!0,valueValidator:function a(){},didChange:f},this._onAny(function(){},c,function(){b.set(a,g())}),f(h,void 0)&&this._firePropChangeEvent(a,h,void 0),this},PropsModel.prototype._set=function(a){for(var b=this,c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];if(1===d.length){var h=[];Object.keys(d[0]).forEach(function(a){if(!b._props[a])throw new Error("No such property '".concat(a,"'"))}),Object.keys(d[0]).forEach(a),Object.entries(d[0]).forEach(function(a){var c=_slicedToArray(a,2),d=c[0],e=c[1];b._props[d].valueValidator(e)}),Object.entries(d[0]).forEach(function(a){var c=_slicedToArray(a,2),d=c[0],e=c[1],f=b._props[d].value;b._props[d].value=e,b._props[d].didChange(e,f)&&h.push([d,e,f])}),h.forEach(function(a){return b._firePropChangeEvent.apply(b,_toConsumableArray(a))})}else{var f=d[0],g=d[1];if(!this._props[f])throw new Error("No such property '".concat(f,"'"));a(f),this._props[f].valueValidator(g);var i=this._props[f].value;this._props[f].value=g,this._props[f].didChange(g,i)&&this._firePropChangeEvent(f,g,i)}},PropsModel.prototype._get=function(a,b){if(a(b),!this._props[b])throw new Error("No such property '".concat(b,"'"));return this._props[b].value},PropsModel.prototype._toJSON=function(a){return Object.entries(this._props).filter(function(b){var c=_slicedToArray(b,1),d=c[0];return a(d)}).reduce(function(a,b){var c=_slicedToArray(b,2),d=c[0],e=c[1].value;return a[d]=e,a},{})};function createAccessorNames(a){for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];return c.map(function(b){return"".concat(b).concat(a.replace(/^./,function(a){return a.toUpperCase()}))})}PropsModel.prototype._installAccessors=function(a,b,c,d){for(var e=this,f=Object.keys(d),g=0;g<f.length;g++){var h=f[g],i=d[h];if(!this._props[h])throw new Error("Cannot create accessors for non-existant property '".concat(h,"'"));switch(i.toLowerCase()){case"readonly":a(h);break;case"readwrite":a(h),b(h);break;case"none":break;default:throw new Error("Unknown access type '".concat(i,"' specified for property '").concat(h,"'"));}}for(var j=Object.keys(d),k=function(){var a,b=j[l],f=d[b];switch(f.toLowerCase()){case"readonly":var g=createAccessorNames(b,"get"),h=_slicedToArray(g,1),i=h[0],k=_defineProperty({},i,function(){return e._props[b].value})[i];c[i]=k;break;case"readwrite":var m=createAccessorNames(b,"get","set"),n=_slicedToArray(m,2),o=n[0],p=n[1],q=(a={},_defineProperty(a,o,function(){return e._props[b].value}),_defineProperty(a,p,function(a){e._set(function(){},b,a)}),a);c[o]=q[o],c[p]=q[p];break;default:}},l=0;l<j.length;l++)k()},PropsModel.prototype._createUtilizer=function(a,b,c){var d=this,e=_toArray(b),f=e.slice(0);return f.forEach(a),f.forEach(function(a){if(!d._props[a])throw new Error("Cannot create utilizer of unknown property '".concat(a,"'"))}),function(){for(var a=arguments.length,b=Array(a),e=0;e<a;e++)b[e]=arguments[e];return c.apply(void 0,_toConsumableArray(f.map(function(a){return d._props[a].value})).concat(b))}},PropsModel.prototype._onAny=function(a,b,c){var d=_toArray(b),e=d.slice(0);e.forEach(a);for(var f=0;f<e.length;f++)this._eventEmitter.on("".concat(e[f],"-changed"),c)},PropsModel.prototype._createChangeHandler=function(a,b,c){var d=_toArray(b),e=d.slice(0),f=this._createUtilizer(a,e,c);return this._onAny(function(){},e,function(){return f()}),f},PropsModel.prototype.createUtilizer=function(a,b){return this._createUtilizer(function(){},a,b)},PropsModel.prototype.onAny=function(a,b){return this._onAny(function(){},a,b)},PropsModel.prototype.createChangeHandler=function(a,b){return this._createChangeHandler(function(){},a,b)},PropsModel.prototype.set=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return this._set.apply(this,[function(){}].concat(b))},PropsModel.prototype.get=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return this._get.apply(this,[function(){}].concat(b))},PropsModel.prototype.toJSON=function(){return this._toJSON(function(){return!0})},PropsModel.prototype.installAccessors=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return this._installAccessors.apply(this,[function(){},function(){}].concat(b))};function propertyCheckerToValidator(a){return function(b){var c=a(b);if(c instanceof Error)throw c;else if(!c)throw new Error("Requested access to property '".concat(b,"' is not allowed"))}}PropsModel.prototype.createApi=function(a){var b=this,c=1<arguments.length&&arguments[1]!==void 0?arguments[1]:propertyCheckerToValidator(a),d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:c;return{get:function f(){for(var a=arguments.length,d=Array(a),e=0;e<a;e++)d[e]=arguments[e];return b._get.apply(b,[c].concat(d))},set:function f(){for(var a=arguments.length,c=Array(a),e=0;e<a;e++)c[e]=arguments[e];return b._set.apply(b,[d].concat(c))},createUtilizer:function f(){for(var a=arguments.length,d=Array(a),e=0;e<a;e++)d[e]=arguments[e];return b._createUtilizer.apply(b,[c].concat(d))},createChangeHandler:function f(){for(var a=arguments.length,d=Array(a),e=0;e<a;e++)d[e]=arguments[e];return b._createChangeHandler.apply(b,[c].concat(d))},installAccessors:function g(){for(var a=arguments.length,e=Array(a),f=0;f<a;f++)e[f]=arguments[f];return b._installAccessors.apply(b,[c,d].concat(e))},toJSON:function c(){return b._toJSON(a)}}};function propNameIsPublic(a){return!a.startsWith("_")}function assertPropNameIsPublic(a){if(!propNameIsPublic(a))throw new Error("Property is not publicly accessible: ".concat(a))}function createStandardWriteValidator(a){return function(b){if(a._props[b].derived)throw new Error("Write access to ".concat(b," is not allowed because the property is a derived property."))}}PropsModel.prototype.getStandardPublicApi=function(){var a=createStandardWriteValidator(this);return this.createApi(propNameIsPublic,assertPropNameIsPublic,function(b){assertPropNameIsPublic(b),a(b)})},PropsModel.prototype.getStandardPrivateApi=function(){return this.createApi(function(){return!0},function(){},createStandardWriteValidator(this))};
{
"name": "props-model",
"version": "0.1.0",
"version": "0.2.0",
"description": "A model for properties including change events and derived properties",

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

@@ -24,4 +24,4 @@ # props-model

```javascript
const PropModel = require('.')
const EventEmitter = require('events')
import PropsModel from 'props-model' // or `const { PropsModel } = require('props-model')`
import EventEmitter from 'events'

@@ -31,3 +31,3 @@ class MutableRectangle {

// Define the properties of this object.
const propModel = new PropModel(new EventEmitter())
const propModel = new PropsModel(new EventEmitter())
// These are "primary" properties, they are not calculated from other properties.

@@ -34,0 +34,0 @@ .defineProp('length', initialLength, isValidDimension)

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