static-params
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -7,8 +7,8 @@ 'use strict'; | ||
const v = []; | ||
for (let c = 0, i = 1, {length} = template; i < length; i++) { | ||
if (values[i - 1] instanceof Static) | ||
t[c] += values[i - 1].v + template[i]; | ||
for (let c = 0, i = 0, j = 0, {length} = values; i < length; i++) { | ||
if (values[i] instanceof Static) | ||
t[c] += values[i].v + template[i + 1]; | ||
else { | ||
v.push(i - 1); | ||
t[++c] = template[i]; | ||
v[j++] = i; | ||
t[++c] = template[i + 1]; | ||
} | ||
@@ -15,0 +15,0 @@ } |
@@ -1,1 +0,1 @@ | ||
self.staticParams=function(t){"use strict";const n=new WeakMap,a=(t,...a)=>{let e=n.get(t);e||n.set(t,e={});const{t:r,v:c}=((t,n)=>{const a=[t[0]],e=[];for(let r=0,c=1,{length:u}=t;c<u;c++)n[c-1]instanceof s?a[r]+=n[c-1].v+t[c]:(e.push(c-1),a[++r]=t[c]);return{t:a,v:e}})(t,a);return(e[r]||(e[r]=[r])).concat(c.map(t=>a[t]))};function s(t){this.v=t}return t.asParams=a,t.asStatic=t=>new s(t),t.asTag=t=>function(){return t.apply(this,a.apply(null,arguments))},t}({}); | ||
self.staticParams=function(t){"use strict";const n=new WeakMap,a=(t,...a)=>{let e=n.get(t);e||n.set(t,e={});const{t:r,v:c}=((t,n)=>{const a=[t[0]],e=[];for(let r=0,c=0,i=0,{length:o}=n;c<o;c++)n[c]instanceof s?a[r]+=n[c].v+t[c+1]:(e[i++]=c,a[++r]=t[c+1]);return{t:a,v:e}})(t,a);return(e[r]||(e[r]=[r])).concat(c.map(t=>a[t]))};function s(t){this.v=t}return t.asParams=a,t.asStatic=t=>new s(t),t.asTag=t=>function(){return t.apply(this,a.apply(null,arguments))},t}({}); |
@@ -6,8 +6,8 @@ const cache = new WeakMap; | ||
const v = []; | ||
for (let c = 0, i = 1, {length} = template; i < length; i++) { | ||
if (values[i - 1] instanceof Static) | ||
t[c] += values[i - 1].v + template[i]; | ||
for (let c = 0, i = 0, j = 0, {length} = values; i < length; i++) { | ||
if (values[i] instanceof Static) | ||
t[c] += values[i].v + template[i + 1]; | ||
else { | ||
v.push(i - 1); | ||
t[++c] = template[i]; | ||
v[j++] = i; | ||
t[++c] = template[i + 1]; | ||
} | ||
@@ -14,0 +14,0 @@ } |
@@ -10,6 +10,6 @@ self.staticParams = (function (exports) { | ||
for (var c = 0, i = 1, length = template.length; i < length; i++) { | ||
if (values[i - 1] instanceof Static) t[c] += values[i - 1].v + template[i];else { | ||
v.push(i - 1); | ||
t[++c] = template[i]; | ||
for (var c = 0, i = 0, j = 0, length = values.length; i < length; i++) { | ||
if (values[i] instanceof Static) t[c] += values[i].v + template[i + 1];else { | ||
v[j++] = i; | ||
t[++c] = template[i + 1]; | ||
} | ||
@@ -16,0 +16,0 @@ } |
@@ -1,1 +0,1 @@ | ||
self.staticParams=function(n){"use strict";var t=new WeakMap,r=function(n,t){for(var r=[n[0]],a=[],u=0,c=1,i=n.length;c<i;c++)t[c-1]instanceof e?r[u]+=t[c-1].v+n[c]:(a.push(c-1),r[++u]=n[c]);return{t:r,v:a}},a=function(n){for(var a=arguments.length,e=new Array(a>1?a-1:0),u=1;u<a;u++)e[u-1]=arguments[u];var c=t.get(n);c||t.set(n,c={});var i=r(n,e),s=i.t,f=i.v;return(c[s]||(c[s]=[s])).concat(f.map((function(n){return e[n]})))};function e(n){this.v=n}return n.asParams=a,n.asStatic=function(n){return new e(n)},n.asTag=function(n){return function(){return n.apply(this,a.apply(null,arguments))}},n}({}); | ||
self.staticParams=function(n){"use strict";var t=new WeakMap,r=function(n,t){for(var r=[n[0]],a=[],u=0,c=0,i=0,s=t.length;c<s;c++)t[c]instanceof e?r[u]+=t[c].v+n[c+1]:(a[i++]=c,r[++u]=n[c+1]);return{t:r,v:a}},a=function(n){for(var a=arguments.length,e=new Array(a>1?a-1:0),u=1;u<a;u++)e[u-1]=arguments[u];var c=t.get(n);c||t.set(n,c={});var i=r(n,e),s=i.t,f=i.v;return(c[s]||(c[s]=[s])).concat(f.map((function(n){return e[n]})))};function e(n){this.v=n}return n.asParams=a,n.asStatic=function(n){return new e(n)},n.asTag=function(n){return function(){return n.apply(this,a.apply(null,arguments))}},n}({}); |
{ | ||
"name": "static-params", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A general purpose utility to allow interpolation values as static parts of a template literal tag", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
@@ -84,1 +84,16 @@ # static-params | ||
``` | ||
## Other usages | ||
While dynamic tags as static part of the template might be the most common use case, this utility makes it possible to actually map anything as static part of a template, even partial chunks. | ||
```js | ||
import {asStatic, asParams} from 'static-params'; | ||
asParams`!${asStatic('<what')}ever ${'wut'}${asStatic('blah')}!`; | ||
// [ [ '!<whatever ', 'blah!' ], 'wut' ] | ||
``` | ||
In few words, there are no limitations regarding which part of the template should be made static, and which part is dynamic, so it is possible to create also invalid templates, but this is just what this library offers. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10700
99