Skip to content
Snippets Groups Projects
Commit 745ae8dd authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

Release 1.20.0

parent ffae3931
Branches
Tags
No related merge requests found
Showing
with 30 additions and 18 deletions
......@@ -2,6 +2,18 @@
All notable changes to this project will be documented in this file.
## [1.20.1] - 2021-10-18
## Fixed
- [closest cannot be used, because closest is not correct for slotted elements](https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/70)
## [1.20.0] - 2021-10-16
## Fixed
- [closest cannot be used, because closest is not correct for slotted elements](https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/70)
## [1.19.0] - 2021-10-16
## Added
......
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{Monster}from"./namespace.js";const PROPERTY_KEY_INTERNALDATA="monsterInternalData";export{Monster,PROPERTY_KEY_INTERNALDATA};
\ No newline at end of file
'use strict';import{Monster}from"./namespace.js";const PROPERTY_KEY_INTERNALDATA="monsterInternalData";export{Monster,PROPERTY_KEY_INTERNALDATA};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";class AbstractConstraint extends Base{constructor(){super()}isValid(s){return Promise.reject(s)}}assignToNamespace("Monster.Constraints",AbstractConstraint);export{Monster,AbstractConstraint};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";class AbstractConstraint extends Base{constructor(){super()}isValid(value){return Promise.reject(value)}}assignToNamespace("Monster.Constraints",AbstractConstraint);export{Monster,AbstractConstraint};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{AbstractConstraint}from"./abstract.js";class AbstractOperator extends AbstractConstraint{constructor(t,r){if(super(),!(t instanceof AbstractConstraint&&r instanceof AbstractConstraint))throw new TypeError("parameters must be from type AbstractConstraint");this.operantA=t,this.operantB=r}}assignToNamespace("Monster.Constraints",AbstractOperator);export{Monster,AbstractOperator};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{AbstractConstraint}from"./abstract.js";class AbstractOperator extends AbstractConstraint{constructor(operantA,operantB){super();if(!(operantA instanceof AbstractConstraint)||!(operantB instanceof AbstractConstraint)){throw new TypeError("parameters must be from type AbstractConstraint")}this.operantA=operantA;this.operantB=operantB}}assignToNamespace("Monster.Constraints",AbstractOperator);export{Monster,AbstractOperator};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{AbstractOperator}from"./abstractoperator.js";class AndOperator extends AbstractOperator{isValid(r){return Promise.all([this.operantA.isValid(r),this.operantB.isValid(r)])}}assignToNamespace("Monster.Constraints",AndOperator);export{Monster,AndOperator};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{AbstractOperator}from"./abstractoperator.js";class AndOperator extends AbstractOperator{isValid(value){return Promise.all([this.operantA.isValid(value),this.operantB.isValid(value)])}}assignToNamespace("Monster.Constraints",AndOperator);export{Monster,AndOperator};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{AbstractConstraint}from"./abstract.js";class Invalid extends AbstractConstraint{isValid(s){return Promise.reject(s)}}assignToNamespace("Monster.Constraints",Invalid);export{Monster,Invalid};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{AbstractConstraint}from"./abstract.js";class Invalid extends AbstractConstraint{isValid(value){return Promise.reject(value)}}assignToNamespace("Monster.Constraints",Invalid);export{Monster,Invalid};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{isArray}from"../types/is.js";import{AbstractConstraint}from"./abstract.js";class IsArray extends AbstractConstraint{isValid(s){return isArray(s)?Promise.resolve(s):Promise.reject(s)}}assignToNamespace("Monster.Constraints",IsArray);export{Monster,IsArray};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{isArray}from"../types/is.js";import{AbstractConstraint}from"./abstract.js";class IsArray extends AbstractConstraint{isValid(value){if(isArray(value)){return Promise.resolve(value)}return Promise.reject(value)}}assignToNamespace("Monster.Constraints",IsArray);export{Monster,IsArray};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{isObject}from"../types/is.js";import{AbstractConstraint}from"./abstract.js";class IsObject extends AbstractConstraint{isValid(s){return isObject(s)?Promise.resolve(s):Promise.reject(s)}}assignToNamespace("Monster.Constraints",IsObject);export{Monster,IsObject};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{isObject}from"../types/is.js";import{AbstractConstraint}from"./abstract.js";class IsObject extends AbstractConstraint{isValid(value){if(isObject(value)){return Promise.resolve(value)}return Promise.reject(value)}}assignToNamespace("Monster.Constraints",IsObject);export{Monster,IsObject};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";const namespace="Monster.Constraints";export{namespace};
\ No newline at end of file
'use strict';export const namespace="Monster.Constraints";
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{AbstractOperator}from"./abstractoperator.js";class OrOperator extends AbstractOperator{isValid(s){var o=this;return new Promise(function(t,r){let a,e;o.operantA.isValid(s).then(function(){t()}).catch(function(){(a=!1)===e&&r()}),o.operantB.isValid(s).then(function(){t()}).catch(function(){(e=!1)===a&&r()})})}}assignToNamespace("Monster.Constraints",OrOperator);export{Monster,OrOperator};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{AbstractOperator}from"./abstractoperator.js";class OrOperator extends AbstractOperator{isValid(value){var self=this;return new Promise(function(resolve,reject){let a,b;self.operantA.isValid(value).then(function(){resolve()}).catch(function(){a=false;if(b===false){reject()}});self.operantB.isValid(value).then(function(){resolve()}).catch(function(){b=false;if(a===false){reject()}})})}}assignToNamespace("Monster.Constraints",OrOperator);export{Monster,OrOperator};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{AbstractConstraint}from"./abstract.js";class Valid extends AbstractConstraint{isValid(s){return Promise.resolve(s)}}assignToNamespace("Monster.Constraints",Valid);export{Monster,Valid};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{AbstractConstraint}from"./abstract.js";class Valid extends AbstractConstraint{isValid(value){return Promise.resolve(value)}}assignToNamespace("Monster.Constraints",Valid);export{Monster,Valid};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{isFunction,isObject,isString}from"../types/is.js";import{validateString}from"../types/validate.js";import{clone}from"../util/clone.js";import{DELIMITER,Pathfinder,WILDCARD}from"./pathfinder.js";function buildMap(t,e,a,n,r){const o=new Map;let i;if(isFunction(e)){if(i=e(t),!(i instanceof Map))throw new TypeError("the selector callback must return a map")}else{if(!isString(e))throw new TypeError("value is neither a string nor a function");i=new Map,buildFlatMap.call(i,t,e)}return i instanceof Map&&i.forEach((t,e,i)=>{isFunction(r)&&!0!==r.call(i,t,e)||(e=build(t,n,e),t=build(t,a),o.set(e,t))}),o}function buildFlatMap(i,t,a,n){var r=this;const o=new Map;var e=r.size;void 0===a&&(a=[]);let l=t.split(DELIMITER),s,p=[];do{if(s=l.shift(),p.push(s),s===WILDCARD){let t=new Pathfinder(i),e;try{e=t.getVia(p.join(DELIMITER))}catch(t){e=new Map}for(const[d,h]of e){let e=clone(a);p.map(t=>{e.push(t===WILDCARD?d:t)});var c=e.join(DELIMITER);let t=buildFlatMap.call(r,h,l.join(DELIMITER),e,h);isObject(t)&&(t["^"]=n),o.set(c,t)}}}while(0<l.length);if(e===r.size)for(var[f,u]of o)r.set(f,u);return i}function build(t,a,n){if(void 0===a)return n||t;validateString(a);const e=[...a.matchAll(/(?<placeholder>\${(?<path>[a-z\^A-Z.\-_0-9]*)})/gm)];let r=new Pathfinder(t);return 0===e.length?r.getVia(a):(e.forEach(e=>{var i=e?.groups,e=i?.placeholder;if(void 0!==e){i=i?.path;let t=r.getVia(i);void 0===t&&(t=n),a=a.replaceAll(e,t)}}),a)}assignToNamespace("Monster.Data",buildMap);export{Monster,buildMap};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{isFunction,isObject,isString}from"../types/is.js";import{validateString}from"../types/validate.js";import{clone}from"../util/clone.js";import{DELIMITER,Pathfinder,WILDCARD}from"./pathfinder.js";function buildMap(subject,selector,valueTemplate,keyTemplate,filter){const result=new Map;let map;if(isFunction(selector)){map=selector(subject);if(!(map instanceof Map)){throw new TypeError("the selector callback must return a map")}}else if(isString(selector)){map=new Map;buildFlatMap.call(map,subject,selector)}else{throw new TypeError("value is neither a string nor a function")}if(!(map instanceof Map)){return result}map.forEach((v,k,m)=>{if(isFunction(filter)){if(filter.call(m,v,k)!==true)return}k=build(v,keyTemplate,k);v=build(v,valueTemplate);result.set(k,v)});return result}function buildFlatMap(subject,selector,key,parentMap){const result=this;const currentMap=new Map;const resultLength=result.size;if(key===undefined)key=[];let parts=selector.split(DELIMITER);let current="",currentPath=[];do{current=parts.shift();currentPath.push(current);if(current===WILDCARD){let finder=new Pathfinder(subject);let map;try{map=finder.getVia(currentPath.join(DELIMITER))}catch(e){let a=e;map=new Map}for(const[k,o]of map){let copyKey=clone(key);currentPath.map(a=>{copyKey.push(a===WILDCARD?k:a)});let kk=copyKey.join(DELIMITER);let sub=buildFlatMap.call(result,o,parts.join(DELIMITER),copyKey,o);if(isObject(sub)){sub["^"]=parentMap}currentMap.set(kk,sub)}}}while(parts.length>0);if(resultLength===result.size){for(const[k,o]of currentMap){result.set(k,o)}}return subject}function build(subject,definition,defaultValue){if(definition===undefined)return defaultValue?defaultValue:subject;validateString(definition);const regexp=/(?<placeholder>\${(?<path>[a-z\^A-Z.\-_0-9]*)})/gm;const array=[...definition.matchAll(regexp)];let finder=new Pathfinder(subject);if(array.length===0){return finder.getVia(definition)}array.forEach(a=>{let groups=a?.["groups"];let placeholder=groups?.["placeholder"];if(placeholder===undefined)return;let path=groups?.["path"];let v=finder.getVia(path);if(v===undefined)v=defaultValue;definition=definition.replaceAll(placeholder,v)});return definition}assignToNamespace("Monster.Data",buildMap);export{Monster,buildMap};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{isArray,isObject}from"../types/is.js";import{typeOf}from"../types/typeof.js";function Diff(e,t){return doDiff(e,t)}function getKeys(e,t,n){if(isArray(n)){const o=e.length>t.length?new Array(e.length):new Array(t.length);return o.fill(0),new Set(o.map((e,t)=>t))}return new Set(Object.keys(e).concat(Object.keys(t)))}function doDiff(t,n,e,o){var r=typeOf(t),s=typeOf(n);const a=e||[],i=o||[];return r!==s||"object"!==r&&"array"!==r?void 0!==(s=getOperator(t,n,r,s))&&i.push(buildResult(t,n,s,e)):getKeys(t,n,r).forEach(e=>{Object.prototype.hasOwnProperty.call(t,e)?Object.prototype.hasOwnProperty.call(n,e)?doDiff(t[e],n[e],a.concat(e),i):i.push(buildResult(t[e],n[e],"delete",a.concat(e))):i.push(buildResult(t[e],n[e],"add",a.concat(e)))}),i}function buildResult(e,t,n,o){const r={operator:n,path:o};return"add"!==n&&(r.first={value:e,type:typeof e},!isObject(e)||void 0!==(e=Object.getPrototypeOf(e)?.constructor?.name)&&(r.first.instance=e)),"add"!==n&&"update"!==n||(r.second={value:t,type:typeof t},!isObject(t)||void 0!==(t=Object.getPrototypeOf(t)?.constructor?.name)&&(r.second.instance=t)),r}function isNotEqual(e,t){return typeof e!=typeof t||(e instanceof Date&&t instanceof Date?e.getTime()!==t.getTime():e!==t)}function getOperator(e,t){let n;var o=typeof e,r=typeof t;return"undefined"==o&&"undefined"!=r?n="add":"undefined"!=o&&"undefined"==r?n="delete":isNotEqual(e,t)&&(n="update"),n}assignToNamespace("Monster.Data",Diff);export{Monster,Diff};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{isArray,isObject}from"../types/is.js";import{typeOf}from"../types/typeof.js";function Diff(first,second){return doDiff(first,second)}function getKeys(a,b,type){if(isArray(type)){const keys=a.length>b.length?new Array(a.length):new Array(b.length);keys.fill(0);return new Set(keys.map((_,i)=>i))}return new Set(Object.keys(a).concat(Object.keys(b)))}function doDiff(a,b,path,diff){let typeA=typeOf(a);let typeB=typeOf(b);const currPath=path||[];const currDiff=diff||[];if(typeA===typeB&&(typeA==="object"||typeA==="array")){getKeys(a,b,typeA).forEach(v=>{if(!Object.prototype.hasOwnProperty.call(a,v)){currDiff.push(buildResult(a[v],b[v],"add",currPath.concat(v)))}else if(!Object.prototype.hasOwnProperty.call(b,v)){currDiff.push(buildResult(a[v],b[v],"delete",currPath.concat(v)))}else{doDiff(a[v],b[v],currPath.concat(v),currDiff)}})}else{const o=getOperator(a,b,typeA,typeB);if(o!==undefined){currDiff.push(buildResult(a,b,o,path))}}return currDiff}function buildResult(a,b,operator,path){const result={operator,path};if(operator!=="add"){result.first={value:a,type:typeof a};if(isObject(a)){const name=Object.getPrototypeOf(a)?.constructor?.name;if(name!==undefined){result.first.instance=name}}}if(operator==="add"||operator==="update"){result.second={value:b,type:typeof b};if(isObject(b)){const name=Object.getPrototypeOf(b)?.constructor?.name;if(name!==undefined){result.second.instance=name}}}return result}function isNotEqual(a,b){if(typeof a!==typeof b){return true}if(a instanceof Date&&b instanceof Date){return a.getTime()!==b.getTime()}return a!==b}function getOperator(a,b){let operator;let typeA=typeof a;let typeB=typeof b;if(typeA==="undefined"&&typeB!=="undefined"){operator="add"}else if(typeA!=="undefined"&&typeB==="undefined"){operator="delete"}else if(isNotEqual(a,b)){operator="update"}return operator}assignToNamespace("Monster.Data",Diff);export{Monster,Diff};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{isArray,isObject}from"../types/is.js";import{typeOf}from"../types/typeof.js";function extend(){let e,r;for(r=0;r<arguments.length;r++){var t=arguments[r];if(!isObject(t)&&!isArray(t))throw new Error("unsuported argument "+JSON.stringify(t));if(void 0!==e)for(var s in t){var i=t?.[s];if(i!==e?.[s])if(isObject(i)||isArray(i)){if(void 0===e[s]&&(isArray(i)?e[s]=[]:e[s]={}),typeOf(e[s])!==typeOf(i))throw new Error("type mismatch: "+JSON.stringify(e[s])+" != "+JSON.stringify(i));e[s]=extend(e[s],i)}else e[s]=i}else e=t}return e}assignToNamespace("Monster.Data",extend);export{Monster,extend};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{isArray,isObject}from"../types/is.js";import{typeOf}from"../types/typeof.js";function extend(){let o,i;for(i=0;i<arguments.length;i++){let a=arguments[i];if(!(isObject(a)||isArray(a))){throw new Error("unsuported argument "+JSON.stringify(a))}if(o===undefined){o=a;continue}for(let k in a){let v=a?.[k];if(v===o?.[k]){continue}if(isObject(v)||isArray(v)){if(o[k]===undefined){if(isArray(v)){o[k]=[]}else{o[k]={}}}if(typeOf(o[k])!==typeOf(v)){throw new Error("type mismatch: "+JSON.stringify(o[k])+" != "+JSON.stringify(v))}o[k]=extend(o[k],v)}else{o[k]=v}}}return o}assignToNamespace("Monster.Data",extend);export{Monster,extend};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";const namespace="Monster.Data";export{namespace};
\ No newline at end of file
'use strict';export const namespace="Monster.Data";
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{isArray,isInteger,isObject,isPrimitive}from"../types/is.js";import{Stack}from"../types/stack.js";import{validateInteger,validateString}from"../types/validate.js";const DELIMITER=".",WILDCARD="*";class Pathfinder extends Base{constructor(t){if(super(),isPrimitive(t))throw new Error("the parameter must not be a simple type");this.object=t,this.wildCard=WILDCARD}setWildCard(t){return validateString(t),this.wildCard=t,this}getVia(t){return getValueViaPath.call(this,this.object,validateString(t))}setVia(t,e){return validateString(t),setValueViaPath.call(this,this.object,t,e),this}deleteVia(t){return validateString(t),deleteValueViaPath.call(this,this.object,t),this}exists(t){validateString(t);try{return getValueViaPath.call(this,this.object,t,!0),!0}catch(t){}return!1}}function iterate(t,e,a){const i=new Map;if(isObject(t)||isArray(t))for(var[r,s]of Object.entries(t))i.set(r,getValueViaPath.call(this,s,e,a));else{var n=e.split(DELIMITER).shift();i.set(n,getValueViaPath.call(this,t,e,a))}return i}function getValueViaPath(e,t,a){if(""===t)return e;let i=t.split(DELIMITER),r=i.shift();if(r===this.wildCard)return iterate.call(this,e,i.join(DELIMITER),a);if(isObject(e)||isArray(e)){let t;if(e instanceof Map||e instanceof WeakMap)t=e.get(r);else if(e instanceof Set||e instanceof WeakSet)r=parseInt(r),validateInteger(r),t=[...e][r];else{if("function"==typeof WeakRef&&e instanceof WeakRef)throw Error("unsupported action for this data type");t=(isArray(e)&&(r=parseInt(r),validateInteger(r)),e?.[r])}if(isObject(t)||isArray(t))return getValueViaPath.call(this,t,i.join(DELIMITER),a);if(0<i.length)throw Error("the journey is not at its end ("+i.join(DELIMITER)+")");if(!0===a&&!e.hasOwnProperty(r))throw Error("unknown value");return t}throw TypeError("unsupported type "+typeof e)}function setValueViaPath(e,t,a){validateString(t);let i=t.split(DELIMITER),r=i.pop();var s,t=i.join(DELIMITER);let n=new Stack,o=t;for(;;){try{getValueViaPath.call(this,e,o,!0);break}catch(t){}if(n.push(o),i.pop(),o=i.join(DELIMITER),""===o)break}for(;!n.isEmpty();){o=n.pop();let t={};n.isEmpty()||(s=n.peek().split(DELIMITER).pop(),isInteger(parseInt(s))&&(t=[])),setValueViaPath.call(this,e,o,t)}let l=getValueViaPath.call(this,e,t);if(!isObject(e)&&!isArray(e))throw TypeError("unsupported type: "+typeof e);if(l instanceof Map||l instanceof WeakMap)l.set(r,a);else if(l instanceof Set||l instanceof WeakSet)l.append(a);else{if("function"==typeof WeakRef&&l instanceof WeakRef)throw Error("unsupported action for this data type");isArray(l)&&(r=parseInt(r),validateInteger(r)),assignProperty(l,r,a)}}function assignProperty(t,e,a){t.hasOwnProperty(e)&&void 0===a&&delete t[e],t[e]=a}function deleteValueViaPath(t,e){const a=e.split(DELIMITER);let i=a.pop();e=a.join(DELIMITER);const r=getValueViaPath.call(this,t,e);if(r instanceof Map)r.delete(i);else{if(r instanceof Set||r instanceof WeakMap||r instanceof WeakSet||"function"==typeof WeakRef&&r instanceof WeakRef)throw Error("unsupported action for this data type");isArray(r)&&(i=parseInt(i),validateInteger(i)),delete r[i]}}assignToNamespace("Monster.Data",Pathfinder);export{DELIMITER,WILDCARD,Monster,Pathfinder};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{isArray,isInteger,isObject,isPrimitive}from"../types/is.js";import{Stack}from"../types/stack.js";import{validateInteger,validateString}from"../types/validate.js";export const DELIMITER=".";export const WILDCARD="*";class Pathfinder extends Base{constructor(object){super();if(isPrimitive(object)){throw new Error("the parameter must not be a simple type")}this.object=object;this.wildCard=WILDCARD}setWildCard(wildcard){validateString(wildcard);this.wildCard=wildcard;return this}getVia(path){return getValueViaPath.call(this,this.object,validateString(path))}setVia(path,value){validateString(path);setValueViaPath.call(this,this.object,path,value);return this}deleteVia(path){validateString(path);deleteValueViaPath.call(this,this.object,path);return this}exists(path){validateString(path);try{getValueViaPath.call(this,this.object,path,true);return true}catch(e){}return false}}assignToNamespace("Monster.Data",Pathfinder);export{Monster,Pathfinder};function iterate(subject,path,check){const result=new Map;if(isObject(subject)||isArray(subject)){for(const[key,value]of Object.entries(subject)){result.set(key,getValueViaPath.call(this,value,path,check))}}else{let key=path.split(DELIMITER).shift();result.set(key,getValueViaPath.call(this,subject,path,check))}return result}function getValueViaPath(subject,path,check){if(path===""){return subject}let parts=path.split(DELIMITER);let current=parts.shift();if(current===this.wildCard){return iterate.call(this,subject,parts.join(DELIMITER),check)}if(isObject(subject)||isArray(subject)){let anchor;if(subject instanceof Map||subject instanceof WeakMap){anchor=subject.get(current)}else if(subject instanceof Set||subject instanceof WeakSet){current=parseInt(current);validateInteger(current);anchor=[...subject]?.[current]}else if(typeof WeakRef==="function"&&subject instanceof WeakRef){throw Error("unsupported action for this data type")}else if(isArray(subject)){current=parseInt(current);validateInteger(current);anchor=subject?.[current]}else{anchor=subject?.[current]}if(isObject(anchor)||isArray(anchor)){return getValueViaPath.call(this,anchor,parts.join(DELIMITER),check)}if(parts.length>0){throw Error("the journey is not at its end ("+parts.join(DELIMITER)+")")}if(check===true&&!subject.hasOwnProperty(current)){throw Error("unknown value")}return anchor}throw TypeError("unsupported type "+typeof subject)}function setValueViaPath(object,path,value){validateString(path);let parts=path.split(DELIMITER);let last=parts.pop();let subpath=parts.join(DELIMITER);let stack=new Stack;let current=subpath;while(true){try{getValueViaPath.call(this,object,current,true);break}catch(e){}stack.push(current);parts.pop();current=parts.join(DELIMITER);if(current==="")break}while(!stack.isEmpty()){current=stack.pop();let obj={};if(!stack.isEmpty()){let n=stack.peek().split(DELIMITER).pop();if(isInteger(parseInt(n))){obj=[]}}setValueViaPath.call(this,object,current,obj)}let anchor=getValueViaPath.call(this,object,subpath);if(!isObject(object)&&!isArray(object)){throw TypeError("unsupported type: "+typeof object)}if(anchor instanceof Map||anchor instanceof WeakMap){anchor.set(last,value)}else if(anchor instanceof Set||anchor instanceof WeakSet){anchor.append(value)}else if(typeof WeakRef==="function"&&anchor instanceof WeakRef){throw Error("unsupported action for this data type")}else if(isArray(anchor)){last=parseInt(last);validateInteger(last);assignProperty(anchor,last,value)}else{assignProperty(anchor,last,value)}}function assignProperty(object,key,value){if(!object.hasOwnProperty(key)){object[key]=value;return}if(value===undefined){delete object[key]}object[key]=value}function deleteValueViaPath(object,path){const parts=path.split(DELIMITER);let last=parts.pop();const subpath=parts.join(DELIMITER);const anchor=getValueViaPath.call(this,object,subpath);if(anchor instanceof Map){anchor.delete(last)}else if(anchor instanceof Set||anchor instanceof WeakMap||anchor instanceof WeakSet||typeof WeakRef==="function"&&anchor instanceof WeakRef){throw Error("unsupported action for this data type")}else if(isArray(anchor)){last=parseInt(last);validateInteger(last);delete anchor[last]}else{delete anchor[last]}}
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateString}from"../types/validate.js";import{Transformer}from"./transformer.js";const DELIMITER="|";class Pipe extends Base{constructor(e){super(),validateString(e),this.pipe=e.split(DELIMITER).map(e=>new Transformer(e))}setCallback(e,s,r){for(var[,t]of Object.entries(this.pipe))t.setCallback(e,s,r);return this}run(e){return this.pipe.reduce((e,s,r,t)=>s.run(e),e)}}assignToNamespace("Monster.Data",Pipe);export{Monster,Pipe};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateString}from"../types/validate.js";import{Transformer}from"./transformer.js";const DELIMITER="|";class Pipe extends Base{constructor(pipe){super();validateString(pipe);this.pipe=pipe.split(DELIMITER).map(v=>{return new Transformer(v)})}setCallback(name,callback,context){for(const[,t]of Object.entries(this.pipe)){t.setCallback(name,callback,context)}return this}run(value){return this.pipe.reduce((accumulator,transformer,currentIndex,array)=>{return transformer.run(accumulator)},value)}}assignToNamespace("Monster.Data",Pipe);export{Monster,Pipe};
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{getGlobal}from"../types/global.js";import{ID}from"../types/id.js";import{isArray,isObject,isString}from"../types/is.js";import{validateFunction,validateInteger,validateObject,validatePrimitive,validateString}from"../types/validate.js";import{clone}from"../util/clone.js";import{Pathfinder}from"./pathfinder.js";class Transformer extends Base{constructor(e){super(),validateString(e),this.args=disassemble(e),this.command=this.args.shift(),this.callbacks=new Map}setCallback(e,t,r){return validateString(e),validateFunction(t),void 0!==r&&validateObject(r),this.callbacks.set(e,{callback:t,context:r}),this}run(e){return transform.apply(this,[e])}}function disassemble(e){validateString(e);let a=new Map;var t;for(t of e.matchAll(/((?<pattern>\\(?<char>.)){1})/gim)){var r,s,n=t?.groups;isObject(n)&&(s=n?.char,(r=n?.pattern)&&s&&(n="__"+(new ID).toString()+"__",a.set(n,s),e=e.replace(r,n)))}let i=e.split(":");return i=i.map(function(e){let t=e.trim();for(var r of a)t=t.replace(r[0],r[1]);return t}),i}function convertToString(e){return isObject(e)&&e.hasOwnProperty("toString")&&(e=e.toString()),validateString(e),e}function transform(s){let n=clone(this.args),i;switch(this.command){case"static":return this.args.join(":");case"tolower":case"strtolower":case"tolowercase":return validateString(s),s.toLowerCase();case"toupper":case"strtoupper":case"touppercase":return validateString(s),s.toUpperCase();case"tostring":return""+s;case"tointeger":var o=parseInt(s);return validateInteger(o),o;case"tojson":return JSON.stringify(s);case"fromjson":return JSON.parse(s);case"trim":return validateString(s),s.trim();case"rawurlencode":return validateString(s),encodeURIComponent(s).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A");case"call":let e;var c=n.shift();let t=getGlobal();return isObject(s)&&s.hasOwnProperty(c)?e=s[c]:this.callbacks.has(c)?(o=this.callbacks.get(c),e=o?.callback,t=o?.context):"object"==typeof window&&window.hasOwnProperty(c)&&(e=window[c]),validateFunction(e),n.unshift(s),e.call(t,...n);case"plain":case"plaintext":return validateString(s),(new DOMParser).parseFromString(s,"text/html").body.textContent||"";case"if":case"?":validatePrimitive(s);let r=n.shift()||void 0,a=n.shift()||void 0;return"value"===r&&(r=s),"\\value"===r&&(r="value"),"value"===a&&(a=s),"\\value"===a&&(a="value"),void 0!==s&&""!==s&&"off"!==s&&"false"!==s&&!1!==s||"on"===s||"true"===s||!0===s?r:a;case"ucfirst":return validateString(s),s.charAt(0).toUpperCase()+s.substr(1);case"ucwords":return validateString(s),s.replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g,function(e){return e.toUpperCase()});case"count":case"length":if((isString(s)||isObject(s)||isArray(s))&&s.hasOwnProperty("length"))return s.length;throw new TypeError("unsupported type "+typeof s);case"base64":return convertToString(s),btoa(s);case"empty":return"";case"undefined":return;case"prefix":return validateString(s),n?.[0]+s;case"suffix":return validateString(s),s+n?.[0];case"uniqid":return(new ID).toString();case"key":case"property":case"index":i=n.shift()||"undefined";var l=n.shift()||"";if(s instanceof Map)return s.has(i)?s.get(i):l;if(isObject(s)||isArray(s))return s?.[i]||l;throw new Error("type not supported");case"path":return i=n.shift()||"undefined",new Pathfinder(s).getVia(i);case"substring":validateString(s);c=parseInt(n[0])||0,l=(parseInt(n[1])||0)+c;return s.substring(c,l);case"nop":return s;case"default":return void 0!==s?s:n[0];default:throw new Error("unknown command "+this.command)}return s}assignToNamespace("Monster.Data",Transformer);export{Monster,Transformer};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{getGlobal}from"../types/global.js";import{ID}from"../types/id.js";import{isArray,isObject,isString}from"../types/is.js";import{validateFunction,validateInteger,validateObject,validatePrimitive,validateString}from"../types/validate.js";import{clone}from"../util/clone.js";import{Pathfinder}from"./pathfinder.js";class Transformer extends Base{constructor(definition){super();validateString(definition);this.args=disassemble(definition);this.command=this.args.shift();this.callbacks=new Map}setCallback(name,callback,context){validateString(name);validateFunction(callback);if(context!==undefined){validateObject(context)}this.callbacks.set(name,{callback:callback,context:context});return this}run(value){return transform.apply(this,[value])}}assignToNamespace("Monster.Data",Transformer);export{Monster,Transformer};function disassemble(command){validateString(command);let placeholder=new Map;const regex=/((?<pattern>\\(?<char>.)){1})/mig;let result=command.matchAll(regex);for(let m of result){let g=m?.["groups"];if(!isObject(g)){continue}let p=g?.["pattern"];let c=g?.["char"];if(p&&c){let r="__"+new ID().toString()+"__";placeholder.set(r,c);command=command.replace(p,r)}}let parts=command.split(":");parts=parts.map(function(value){let v=value.trim();for(let k of placeholder){v=v.replace(k[0],k[1])}return v});return parts}function convertToString(value){if(isObject(value)&&value.hasOwnProperty("toString")){value=value.toString()}validateString(value);return value}function transform(value){let args=clone(this.args);let key;switch(this.command){case"static":return this.args.join(":");case"tolower":case"strtolower":case"tolowercase":validateString(value);return value.toLowerCase();case"toupper":case"strtoupper":case"touppercase":validateString(value);return value.toUpperCase();case"tostring":return""+value;case"tointeger":let n=parseInt(value);validateInteger(n);return n;case"tojson":return JSON.stringify(value);case"fromjson":return JSON.parse(value);case"trim":validateString(value);return value.trim();case"rawurlencode":validateString(value);return encodeURIComponent(value).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A");case"call":let callback;let callbackName=args.shift();let context=getGlobal();if(isObject(value)&&value.hasOwnProperty(callbackName)){callback=value[callbackName]}else if(this.callbacks.has(callbackName)){let s=this.callbacks.get(callbackName);callback=s?.["callback"];context=s?.["context"]}else if(typeof window==="object"&&window.hasOwnProperty(callbackName)){callback=window[callbackName]}validateFunction(callback);args.unshift(value);return callback.call(context,...args);case"plain":case"plaintext":validateString(value);let doc=new DOMParser().parseFromString(value,"text/html");return doc.body.textContent||"";case"if":case"?":validatePrimitive(value);let trueStatement=args.shift()||undefined;let falseStatement=args.shift()||undefined;if(trueStatement==="value"){trueStatement=value}if(trueStatement==="\\value"){trueStatement="value"}if(falseStatement==="value"){falseStatement=value}if(falseStatement==="\\value"){falseStatement="value"}let condition=value!==undefined&&value!==""&&value!=="off"&&value!=="false"&&value!==false||value==="on"||value==="true"||value===true;return condition?trueStatement:falseStatement;case"ucfirst":validateString(value);let firstchar=value.charAt(0).toUpperCase();return firstchar+value.substr(1);case"ucwords":validateString(value);return value.replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g,function(v){return v.toUpperCase()});case"count":case"length":if((isString(value)||isObject(value)||isArray(value))&&value.hasOwnProperty("length")){return value.length}throw new TypeError("unsupported type "+typeof value);case"base64":convertToString(value);return btoa(value);case"empty":return"";case"undefined":return undefined;case"prefix":validateString(value);let prefix=args?.[0];return prefix+value;case"suffix":validateString(value);let suffix=args?.[0];return value+suffix;case"uniqid":return new ID().toString();case"key":case"property":case"index":key=args.shift()||"undefined";let defaultValue=args.shift()||"";if(value instanceof Map){if(!value.has(key)){return defaultValue}return value.get(key)}if(isObject(value)||isArray(value)){if(value?.[key]){return value?.[key]}return defaultValue}throw new Error("type not supported");case"path":key=args.shift()||"undefined";return new Pathfinder(value).getVia(key);case"substring":validateString(value);let start=parseInt(args[0])||0;let end=(parseInt(args[1])||0)+start;return value.substring(start,end);case"nop":return value;case"default":if(value!==undefined){return value}return args[0];default:throw new Error("unknown command "+this.command);}return value}
/** Monster 1.19.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{getGlobalFunction}from"../types/global.js";import{ProxyObserver}from"../types/proxyobserver.js";import{validateInstance,validateString}from"../types/validate.js";const ATTRIBUTEPREFIX="data-monster-";class Assembler extends Base{constructor(e){super(),this.attributePrefix=ATTRIBUTEPREFIX,validateInstance(e,getGlobalFunction("DocumentFragment")),this.fragment=e}setAttributePrefix(e){return validateString(e),this.attributePrefix=e,this}getAttributePrefix(){return this.attributePrefix}createDocumentFragment(e){return void 0===e&&(e=new ProxyObserver({})),validateInstance(e,ProxyObserver),this.fragment.cloneNode(!0)}}assignToNamespace("Monster.DOM",Assembler);export{Monster,ATTRIBUTEPREFIX,Assembler};
\ No newline at end of file
'use strict';import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{getGlobalFunction}from"../types/global.js";import{ProxyObserver}from"../types/proxyobserver.js";import{validateInstance,validateString}from"../types/validate.js";const ATTRIBUTEPREFIX="data-monster-";class Assembler extends Base{constructor(fragment){super();this.attributePrefix=ATTRIBUTEPREFIX;validateInstance(fragment,getGlobalFunction("DocumentFragment"));this.fragment=fragment}setAttributePrefix(prefix){validateString(prefix);this.attributePrefix=prefix;return this}getAttributePrefix(){return this.attributePrefix}createDocumentFragment(data){if(data===undefined){data=new ProxyObserver({})}validateInstance(data,ProxyObserver);let fragment=this.fragment.cloneNode(true);return fragment}}assignToNamespace("Monster.DOM",Assembler);export{Monster,ATTRIBUTEPREFIX,Assembler};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment