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

@gullerya/i18n

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gullerya/i18n - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

2

dist/data-tier/data-tier.min.js

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

import{ensureObservable,DEFAULT_TIE_TARGET_PROVIDER,getTargetProperty,extractViewParams,CHANGE_EVENT_NAME_PROVIDER,addChangeListener,delChangeListener,getPath,setPath,setViewProperty,callViewFunction}from"./dt-utils.min.js";export{DEFAULT_TIE_TARGET_PROVIDER,CHANGE_EVENT_NAME_PROVIDER};export const ties=new Ties;export const addRootDocument=e=>{if(!e||Node.DOCUMENT_NODE!==e.nodeType&&Node.DOCUMENT_FRAGMENT_NODE!==e.nodeType)throw new Error("invalid argument, NULL or not one of: DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE");return roots.has(e)?(console.warn("any root document may be added only once"),!1):(initDocumentObserver(e),addTree(e),roots.add(e),!0)};export const removeRootDocument=e=>roots.has(e)?(dropTree(e),roots.delete(e),!0):(console.warn("no root document "+e+" known"),!1);console.info("DT: starting initialization...");const initStartTime=performance.now(),ELEMENT_PROCESSED_SYMBOL=Symbol("element-processed"),VIEW_PARAMS_KEY=Symbol("view.params.key"),roots=new WeakSet,views={};class Tie{constructor(e,t){this.key=e,this.model=ensureObservable(t),this.ownModel=this.model!==t,this.observer=Tie.processDataChanges.bind(this),this.model.observe(this.observer),Object.freeze(this)}static processDataChanges(e){const t=this.key,o=this.model,n=views[t],i=Object.keys(n),r={};let s,a,l,c,d,h,f,E,u,m="";if(i.length)for(s=0,a=e.length;s<a;s++){if(c=(l=e[s]).object,d=l.path,!Array.isArray(c)||"insert"!==l.type&&"delete"!==l.type||isNaN(d[d.length-1])){const e=d.length;if(e>1){for(let t=0;t<e-1;t++)m+=d[t]+".";m+=d[e-1]}else 1===e&&(m=d[0])}else{if(r[m=d.slice(0,-1).join(".")]===c)continue;r[m]=c,l=null}for(h=i.length;h;)if(0===(f=i[--h]).indexOf(m))for(u=(E=n[f]).length;u;)updateFromTie(E[--u],m,l,t,o)}}}function Ties(){const e={},t=/^[a-zA-Z0-9]+$/;this.get=function(t){const o=e[t];return o?o.model:void 0},this.create=function(o,n){if(e[o])throw new Error('tie "'+o+'" already exists');if(function(e){if(!e||"string"!=typeof e)throw new Error("tie key MUST be a non empty string");if(!t.test(e))throw new Error("tie key MUST match "+t+'; "'+e+'" is not')}(o),null===n)throw new Error("initial model, when provided, MUST NOT be null");o in views||(views[o]={});const i=new Tie(o,n);return e[o]=i,e[o].observer([{path:[]}]),i.model},this.remove=function(t){let o;if("object"==typeof t)o=Object.keys(e).find(o=>e[o].model===t);else{if("string"!=typeof t)throw new Error("tie to remove MUST either be a valid tie key or tie self");o=t}delete views[o];const n=e[o];n&&(n.model&&n.ownModel&&n.model.revoke(),delete e[o])},Object.freeze(this)}function changeListener(e){const t=e.currentTarget,o=getTargetProperty(t),n=t[VIEW_PARAMS_KEY];let i,r,s,a=n.length;for(;a;)(i=n[--a]).targetProperty===o&&(r=ties.get(i.tieKey))&&(s=t[o],setPath(r,i.path,s))}function add(e){if(e[ELEMENT_PROCESSED_SYMBOL]=!0,e.matches(":defined")){const t=extractViewParams(e);let o;if(t&&(o=t.length)){for(e[VIEW_PARAMS_KEY]=t;o;){const n=t[--o];if(n.isFunctional)n.fParams.forEach(t=>{const o=t.tieKey,n=t.rawPath,i=views[o]||(views[o]={}),r=i[n]||(i[n]=[]);r.indexOf(e)<0&&r.push(e)});else{const t=n.tieKey,o=n.rawPath,i=views[t]||(views[t]={}),r=i[o]||(i[o]=[]);r.indexOf(e)<0&&r.push(e)}}updateFromView(e),addChangeListener(e,changeListener)}e.shadowRoot&&addRootDocument(e.shadowRoot)}else waitUndefined(e)}function waitUndefined(e){let t="";if(e.localName.indexOf("-")>0)t=e.localName;else{const o=/.*is\s*=\s*"([^"]+)"\s*.*/.exec(e.outerHTML);o&&o.length>1&&(t=o[1])}t?customElements.whenDefined(t).then(()=>add(e)):console.warn("failed to determine tag of yet undefined custom element "+e+", abandoning")}function updateFromTie(e,t,o,n,i){const r=e[VIEW_PARAMS_KEY];let s=r.length;for(;s;){const a=r[--s];if(a.isFunctional){if(a.fParams.some(e=>e.tieKey===n&&0===e.rawPath.indexOf(t))){let t=!1;const n=[];a.fParams.forEach(e=>{let o;const i=ties.get(e.tieKey);i&&(o=getPath(i,e.path),t=!0),n.push(o)}),t&&(n.push([o]),callViewFunction(e,a.targetProperty,n))}}else{if(a.tieKey!==n)continue;if(0!==a.rawPath.indexOf(t))continue;let r;o&&void 0!==o.value&&t===a.rawPath?o&&(r=o.value):r=getPath(i,a.path),void 0===r&&(r=""),setViewProperty(e,a.targetProperty,r)}}}function updateFromView(e,t){const o=e[VIEW_PARAMS_KEY];let n=o.length;for(;n;){const i=o[--n];if(i.isFunctional){if(!t||i.fParams.some(e=>0===e.rawPath.indexOf(t))){let t=!1;const o=[];i.fParams.forEach(e=>{let n;const i=ties.get(e.tieKey);i&&(n=getPath(i,e.path),t=!0),o.push(n)}),t&&(o.push(null),callViewFunction(e,i.targetProperty,o))}}else if(!t||0===i.rawPath.indexOf(t)){const t=ties.get(i.tieKey);if(void 0===t)continue;let o=getPath(t,i.path);void 0===o&&(o=""),setViewProperty(e,i.targetProperty,o)}}}function addTree(e){let t;e.childElementCount?(t=Array.from(e.querySelectorAll("*"))).unshift(e):t=[e];let o=t.length;for(;o;)try{const e=t[--o];Node.ELEMENT_NODE!==e.nodeType||e[ELEMENT_PROCESSED_SYMBOL]||add(e)}catch(e){console.error("failed to process/add element",e)}}function dropTree(e){let t;e.childElementCount?(t=Array.from(e.querySelectorAll("*"))).unshift(e):t=[e];let o=t.length;for(;o;){const e=t[--o],n=e[VIEW_PARAMS_KEY];if(n){let t=n.length;for(;t;){const o=n[--t];if(!views[o.tieKey])continue;const i=views[o.tieKey][o.rawPath],r=i.indexOf(e);r>=0&&(i.splice(r,1),delChangeListener(e,changeListener))}delete e[VIEW_PARAMS_KEY]}e.shadowRoot&&removeRootDocument(e.shadowRoot)}}function move(e,t,o){let n,i,r;if(t){for(i=(n=e[VIEW_PARAMS_KEY]).length;i;){const t=n[--i];if(!views[t.tieKey])continue;const o=views[t.tieKey][t.rawPath];o&&(r=o.indexOf(e))>=0&&o.splice(r,1)}delChangeListener(e,changeListener)}if(o&&(n=extractViewParams(e))&&(i=n.length)){for(e[VIEW_PARAMS_KEY]=n;i;){const t=n[--i],o=views[t.tieKey]||(views[t.tieKey]={}),r=o[t.rawPath]||(o[t.rawPath]=[]);r.indexOf(e)<0&&(r.push(e),updateFromView(e,t.rawPath))}addChangeListener(e,changeListener)}}function processDomChanges(e){const t=e.length;let o,n,i,r,s,a,l,c,d,h=0;for(;h<t;h++)if("attributes"===(r=(i=e[h]).type))s=i.attributeName,move(o=i.target,i.oldValue,o.getAttribute(s));else if("childList"===r){for(l=(a=i.addedNodes).length;l;)n=(o=a[--l]).nodeType,Node.ELEMENT_NODE===n&&addTree(o);for(d=(c=i.removedNodes).length;d;)n=(o=c[--d]).nodeType,Node.ELEMENT_NODE===n&&dropTree(o)}}function initDocumentObserver(e){new MutationObserver(processDomChanges).observe(e,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["data-tie"],characterData:!1,characterDataOldValue:!1})}addRootDocument(document),console.info("DT: ... initialization DONE (took "+Math.floor(100*(performance.now()-initStartTime))/100+"ms)");
import{ensureObservable,DEFAULT_TIE_TARGET_PROVIDER,getTargetProperty,extractViewParams,CHANGE_EVENT_NAME_PROVIDER,addChangeListener,delChangeListener,getPath,setPath,setViewProperty,callViewFunction}from"./dt-utils.min.js";export{DEFAULT_TIE_TARGET_PROVIDER,CHANGE_EVENT_NAME_PROVIDER};export const ties=new Ties;export const addRootDocument=e=>{if(!e||Node.DOCUMENT_NODE!==e.nodeType&&Node.DOCUMENT_FRAGMENT_NODE!==e.nodeType)throw new Error("invalid argument, NULL or not one of: DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE");return roots.has(e)?(console.warn("any root document may be added only once"),!1):(initDocumentObserver(e),addTree(e),roots.add(e),!0)};export const removeRootDocument=e=>roots.has(e)?(dropTree(e),roots.delete(e),!0):(console.warn("no root document "+e+" known"),!1);console.info("DT: starting initialization...");const initStartTime=performance.now(),MUTATION_OBSERVER_OPTIONS={childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["data-tie"],characterData:!1,characterDataOldValue:!1},ELEMENT_PROCESSED_SYMBOL=Symbol("element-processed"),VIEW_PARAMS_KEY=Symbol("view.params.key"),roots=new WeakSet,views={};class Tie{constructor(e,t){this.key=e,this.model=ensureObservable(t),this.views=null,this.ownModel=this.model!==t,this.model.observe(e=>this.processDataChanges(e))}processDataChanges(e){const t=this.key,o=this.model,n=this.views||(this.views=views[t]),i=Object.keys(n),r={};let s,a,l,c,d,h,f,E,u,w="";if(i.length)for(s=0,a=e.length;s<a;s++){if(c=(l=e[s]).object,d=l.path,!Array.isArray(c)||"insert"!==l.type&&"delete"!==l.type||isNaN(d[d.length-1])){const e=d.length;if(e>1){for(let t=0;t<e-1;t++)w+=d[t]+".";w+=d[e-1]}else 1===e&&(w=d[0])}else{if(r[w=d.slice(0,-1).join(".")]===c)continue;r[w]=c,l=null}for(h=i.length;h;)if(0===(f=i[--h]).indexOf(w))for(u=(E=n[f]).length;u;)updateFromTie(E[--u],w,l,t,o)}}}function Ties(){const e={},t=/^[a-zA-Z0-9]+$/;this.get=function(t){const o=e[t];return o?o.model:void 0},this.create=function(o,n){if(e[o])throw new Error('tie "'+o+'" already exists');if(function(e){if(!e||"string"!=typeof e)throw new Error("tie key MUST be a non empty string");if(!t.test(e))throw new Error("tie key MUST match "+t+'; "'+e+'" is not')}(o),null===n)throw new Error("initial model, when provided, MUST NOT be null");o in views||(views[o]={});const i=new Tie(o,n);return e[o]=i,e[o].processDataChanges([{path:[]}]),i.model},this.remove=function(t){let o;if("object"==typeof t)o=Object.keys(e).find(o=>e[o].model===t);else{if("string"!=typeof t)throw new Error("tie to remove MUST either be a valid tie key or tie self");o=t}delete views[o];const n=e[o];n&&(n.model&&n.ownModel&&n.model.revoke(),delete e[o])},Object.freeze(this)}function changeListener(e){const t=e.currentTarget,o=getTargetProperty(t),n=t[VIEW_PARAMS_KEY];let i,r,s,a=n.length;for(;a;)(i=n[--a]).targetProperty===o&&(r=ties.get(i.tieKey))&&(s=t[o],setPath(r,i.path,s))}function add(e){if(e[ELEMENT_PROCESSED_SYMBOL]=!0,e.matches(":defined")){const t=extractViewParams(e);let o;if(t&&(o=t.length)){for(e[VIEW_PARAMS_KEY]=t;o;){const n=t[--o];if(n.isFunctional)n.fParams.forEach(t=>{const o=t.tieKey,n=t.rawPath,i=views[o]||(views[o]={}),r=i[n]||(i[n]=[]);r.indexOf(e)<0&&r.push(e)});else{const t=n.tieKey,o=n.rawPath,i=views[t]||(views[t]={}),r=i[o]||(i[o]=[]);r.indexOf(e)<0&&r.push(e)}}updateFromView(e),addChangeListener(e,changeListener)}e.shadowRoot&&addRootDocument(e.shadowRoot)}else waitUndefined(e)}function waitUndefined(e){let t="";if(e.localName.indexOf("-")>0)t=e.localName;else{const o=/.*is\s*=\s*"([^"]+)"\s*.*/.exec(e.outerHTML);o&&o.length>1&&(t=o[1])}t?customElements.whenDefined(t).then(()=>add(e)):console.warn("failed to determine tag of yet undefined custom element "+e+", abandoning")}function updateFromTie(e,t,o,n,i){const r=e[VIEW_PARAMS_KEY];let s=r.length;for(;s;){const a=r[--s];if(a.isFunctional){if(a.fParams.some(e=>e.tieKey===n&&0===e.rawPath.indexOf(t))){let t=!1;const n=[];a.fParams.forEach(e=>{let o;const i=ties.get(e.tieKey);i&&(o=getPath(i,e.path),t=!0),n.push(o)}),t&&(n.push([o]),callViewFunction(e,a.targetProperty,n))}}else{if(a.tieKey!==n)continue;if(0!==a.rawPath.indexOf(t))continue;let r;o&&void 0!==o.value&&t===a.rawPath?o&&(r=o.value):r=getPath(i,a.path),void 0===r&&(r=""),setViewProperty(e,a.targetProperty,r)}}}function updateFromView(e,t){const o=e[VIEW_PARAMS_KEY];let n=o.length;for(;n;){const i=o[--n];if(i.isFunctional){if(!t||i.fParams.some(e=>0===e.rawPath.indexOf(t))){let t=!1;const o=[];i.fParams.forEach(e=>{let n;const i=ties.get(e.tieKey);i&&(n=getPath(i,e.path),t=!0),o.push(n)}),t&&(o.push(null),callViewFunction(e,i.targetProperty,o))}}else if(!t||0===i.rawPath.indexOf(t)){const t=ties.get(i.tieKey);if(void 0===t)continue;let o=getPath(t,i.path);void 0===o&&(o=""),setViewProperty(e,i.targetProperty,o)}}}function addTree(e){let t;e.childElementCount?(t=Array.from(e.querySelectorAll("*"))).unshift(e):t=[e];let o=t.length;for(;o;)try{const e=t[--o];Node.ELEMENT_NODE!==e.nodeType||e[ELEMENT_PROCESSED_SYMBOL]||add(e)}catch(e){console.error("failed to process/add element",e)}}function dropTree(e){let t;e.childElementCount?(t=Array.from(e.querySelectorAll("*"))).unshift(e):t=[e];let o=t.length;for(;o;){const e=t[--o],n=e[VIEW_PARAMS_KEY];if(n){let t=n.length;for(;t;){const o=n[--t];if(!views[o.tieKey])continue;const i=views[o.tieKey][o.rawPath],r=i.indexOf(e);r>=0&&(i.splice(r,1),delChangeListener(e,changeListener))}delete e[VIEW_PARAMS_KEY]}e.shadowRoot&&removeRootDocument(e.shadowRoot)}}function move(e,t,o){let n,i,r;if(t&&(n=e[VIEW_PARAMS_KEY])){for(i=n.length;i;){const t=n[--i];if(!views[t.tieKey])continue;const o=views[t.tieKey][t.rawPath];o&&(r=o.indexOf(e))>=0&&o.splice(r,1)}delChangeListener(e,changeListener)}if(o&&(n=extractViewParams(e))&&(i=n.length)){for(e[VIEW_PARAMS_KEY]=n;i;){const t=n[--i],o=views[t.tieKey]||(views[t.tieKey]={}),r=o[t.rawPath]||(o[t.rawPath]=[]);r.indexOf(e)<0&&(r.push(e),updateFromView(e,t.rawPath))}addChangeListener(e,changeListener)}}function processDomChanges(e){const t=e.length;let o,n,i,r,s,a,l,c,d=0;for(;d<t;d++)if("attributes"===(r=(i=e[d]).type)){const e=i.attributeName,t=i.target,o=i.oldValue,n=t.getAttribute(e);o!==n&&move(t,o,n)}else if("childList"===r){for(a=(s=i.addedNodes).length;a;)n=(o=s[--a]).nodeType,Node.ELEMENT_NODE===n&&addTree(o);for(c=(l=i.removedNodes).length;c;)n=(o=l[--c]).nodeType,Node.ELEMENT_NODE===n&&dropTree(o)}}function initDocumentObserver(e){new MutationObserver(processDomChanges).observe(e,MUTATION_OBSERVER_OPTIONS)}addRootDocument(document),console.info("DT: ... initialization DONE (took "+Math.floor(100*(performance.now()-initStartTime))/100+"ms)");
{
"name": "@gullerya/i18n",
"version": "0.1.0",
"version": "0.2.0",
"description": "client (browser) oriented internationalization library",

@@ -27,2 +27,3 @@ "keywords": [

},
"funding": "https://paypal.me/gullerya?locale.x=en_US",
"repository": {

@@ -38,3 +39,3 @@ "type": "git",

"dependencies": {
"data-tier": "^2.2.0"
"data-tier": "^2.3.1"
},

@@ -49,5 +50,5 @@ "devDependencies": {

"fs-extra": "^8.1.0",
"just-test": "^2.1.3",
"just-test": "^2.2.0",
"uglify-es": "^3.3.9"
}
}
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