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

#20

parent b09e82bc
No related branches found
No related tags found
No related merge requests found
Showing
with 103 additions and 196 deletions
......@@ -4,6 +4,8 @@
<modules>
<module fileurl="file://$PROJECT_DIR$/../../../../alvine/frontend/alvine.frontend.framework/alvine.frontend.alvine.alvine-frontend-framework.iml" filepath="$PROJECT_DIR$/../../../../alvine/frontend/alvine.frontend.framework/alvine.frontend.alvine.alvine-frontend-framework.iml" />
<module fileurl="file://$PROJECT_DIR$/monster.iml" filepath="$PROJECT_DIR$/monster.iml" />
<module fileurl="file://$PROJECT_DIR$/../web-components/template/template.iml" filepath="$PROJECT_DIR$/../web-components/template/template.iml" />
<module fileurl="file://$PROJECT_DIR$/../web-components/multiselect/web-components.multiselect.iml" filepath="$PROJECT_DIR$/../web-components/multiselect/web-components.multiselect.iml" />
</modules>
</component>
</project>
\ No newline at end of file
......@@ -2,7 +2,10 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/packages/monster/source" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/packages/monster/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
......
This diff is collapsed.
......@@ -46,5 +46,8 @@
"uglifycss": "^0.0.29",
"watchify": "^4.0.0",
"webcrypto-core": "^1.2.0"
},
"dependencies": {
"jsdom-global": "^3.0.2"
}
}
......@@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file.
## [1.7.0] - 2021-07-31
### Added
- [new Monster.DOM.CustomElement](https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/20)
## [1.6.0] - 2021-07-29
### Added
......
......@@ -38,7 +38,7 @@ thus supports all browsers that are compatible with ES5.
<script type="module">
import {
Monster
} from 'https://unpkg.com/@schukai/monster@1.6.0/dist/modules/monster.js';
} from 'https://unpkg.com/@schukai/monster@1.7.0/dist/modules/monster.js';
let id = document.getElementById('version');
id.innerHTML = Monster.getVersion();
</script>
......@@ -49,8 +49,8 @@ thus supports all browsers that are compatible with ES5.
nomodule for backwards compatibility
```
<script type="module" src="https://unpkg.com/@schukai/monster@1.6.0/dist/modules/monster.js"></script>
<script nomodule src="https://unpkg.com/@schukai/monster@1.6.0/dist/monster.js"></script>
<script type="module" src="https://unpkg.com/@schukai/monster@1.7.0/dist/modules/monster.js"></script>
<script nomodule src="https://unpkg.com/@schukai/monster@1.7.0/dist/monster.js"></script>
```
### compatibility
......
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{Base}from"../types/base.js";class AbstractConstraint extends Base{constructor(){super()}isValid(value){return Promise.reject(value)}}Monster.assignToNamespace("Monster.Constraints",AbstractConstraint);export{Monster,AbstractConstraint};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,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}}Monster.assignToNamespace("Monster.Constraints",AbstractOperator);export{Monster,AbstractOperator};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,AbstractConstraint}from"./abstract.js";import{AbstractOperator}from"./abstractoperator.js";class AndOperator extends AbstractOperator{isValid(value){return Promise.all([this.operantA.isValid(value),this.operantB.isValid(value)])}}Monster.assignToNamespace("Monster.Constraints",AndOperator);export{Monster,AndOperator};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,AbstractConstraint}from"./abstract.js";class Invalid extends AbstractConstraint{isValid(value){return Promise.reject(value)}}Monster.assignToNamespace("Monster.Constraints",Invalid);export{Monster,Invalid};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,AbstractConstraint}from"./abstract.js";import{isArray}from"../types/is.js";class IsArray extends AbstractConstraint{isValid(value){if(isArray(value)){return Promise.resolve(value)}return Promise.reject(value)}}Monster.assignToNamespace("Monster.Constraints",IsArray);export{Monster,IsArray};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,AbstractConstraint}from"./abstract.js";import{isObject}from"../types/is.js";class IsObject extends AbstractConstraint{isValid(value){if(isObject(value)){return Promise.resolve(value)}return Promise.reject(value)}}Monster.assignToNamespace("Monster.Constraints",IsObject);export{Monster,IsObject};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';const namespace="Monster.Constraints";
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,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()}})})}}Monster.assignToNamespace("Monster.Constraints",OrOperator);export{Monster,OrOperator};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,AbstractConstraint}from"./abstract.js";class Valid extends AbstractConstraint{isValid(value){return Promise.resolve(value)}}Monster.assignToNamespace("Monster.Constraints",Valid);export{Monster,Valid};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster,isArray,isObject}from"../types/is.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"){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}Monster.assignToNamespace("Monster.Data",Diff);export{Monster,Diff};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';const namespace="Monster.Data";
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{isObject,isArray,isInteger}from"../types/is.js";import{validateString,validateInteger}from"../types/validate.js";import{Base}from"../types/base.js";import{Stack}from"../types/stack.js";const DELIMITER=".";class Pathfinder extends Base{constructor(object){super();this.object=object}getVia(path){validateString(path);return getValueViaPath(this.object,path)}setVia(path,value){validateString(path);setValueViaPath(this.object,path,value);return this}deleteVia(path){validateString(path);deleteValueViaPath(this.object,path);return this}exists(path){validateString(path);try{getValueViaPath(this.object,path,true);return true}catch(e){}return false}}Monster.assignToNamespace("Monster.Data",Pathfinder);export{Monster,Pathfinder};function getValueViaPath(object,path,check){if(path===""){return object}let parts=path.split(DELIMITER);let current=parts.shift();if(isObject(object)||isArray(object)){let anchor;if(object instanceof Map||object instanceof WeakMap){anchor=object.get(current)}else if(object instanceof Set||object instanceof WeakSet){current=parseInt(current);validateInteger(current);anchor=[...object]?.[current]}else if(object instanceof WeakRef){throw Error("unsupported action for this data type")}else if(isArray(object)){current=parseInt(current);validateInteger(current);anchor=object?.[current]}else{anchor=object?.[current]}if(isObject(anchor)||isArray(anchor)){return getValueViaPath(anchor,parts.join(DELIMITER),check)}if(parts.length>0){throw Error("the journey is not at its end ("+parts.join(DELIMITER)+")")}if(check===true&&!object.hasOwnProperty(current)){throw Error("unknown value")}return anchor}throw TypeError("unsupported type")}function setValueViaPath(object,path,value){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(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(object,current,obj)}let anchor=getValueViaPath(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(anchor instanceof WeakRef){throw Error("unsupported action for this data type")}else if(isArray(anchor)){last=parseInt(last);validateInteger(last);anchor[last]=value}else{anchor[last]=value}return}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||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]}return}
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{Transformer}from"./transformer.js";import{Base}from"../types/base.js";import{validateString}from"../types/validate.js";const DELIMITER="|";class Pipe extends Base{constructor(pipe){super();validateString(pipe);this.pipe=pipe.split(DELIMITER).map(v=>{return new Transformer(v)})}run(value){return this.pipe.reduce((accumulator,currentValue,currentIndex,array)=>{return currentValue.run(accumulator)},value)}}Monster.assignToNamespace("Monster.Data",Pipe);export{Monster,Pipe};
/** Monster 1.6.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.7.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
'use strict';import{Monster}from"../namespace.js";import{Base}from"../types/base.js";import{validateString,validatePrimitive,validateFunction,validateInteger}from"../types/validate.js";import{isObject,isString,isArray}from"../types/is.js";import{ID}from"../types/id.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){validateString(name);validateFunction(callback);this.callbacks.set(name,callback);return this}run(value){return transform.apply(this,[value])}}Monster.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"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();if(isObject(value)&&calue.hasOwnProperty(callbackName)){callback=value[callbackName]}else if(this.callbacks.has(callbackName)){callback=this.callbacks.get(callbackName)}else if(typeof window==="object"&&window.hasOwnProperty(callbackName)){callback=window[callbackName]}validateFunction(callback);args.unshift(value);return callback(...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");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;default:throw new Error("unknown command");}return value}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment