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

@randajan/jet-base

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@randajan/jet-base - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

183

dist/index.js

@@ -1,2 +0,183 @@

import _ from"@randajan/jet-core";import l from"@randajan/jet-core";var h=new Map,m=n=>h.get(n),F=n=>{h.set(n,{flat:{},fit:{},watch:{},store:{}})},w=(n,t)=>(t=String.jet.to(t,"."),t?m(n).flat[t]:m(n).output),T=(n,t)=>(t===void 0&&l.isRunnable(n)?(t=n,n=""):n=String.jet.to(n,"."),[n,t]),$=(n,t,e,r)=>(n[t][e]=n[t][e]||l.create.RunPool()).add(r),D=(n,t)=>{if(!n)return[...t];let e=[];for(let r of t)r.startsWith(n)&&e.push(r.slice(n.length+1));return e},a=(n,t,e)=>([t,e]=T(t,e),$(m(n),"watch",t,r=>{e(s=>n.get([t,s]),s=>D(t,r))})),b=(n,t,e)=>{[t,e]=T(t,e);let r=m(n),s=$(r,"fit",t,e),o=t?i=>y(n,t,l.digOut(r.input,t)):i=>y(n,t,r.input);return o(),i=>{s(),o()}},y=(n,t,e)=>{let r=m(n),{input:s,output:o,flat:i,fit:g}=r;t=String.jet.to(t,".");let d=(c,f)=>f&&g[f]&&g[f].fit?g[f].fit(c,i[f]):c,j=(c,f)=>d(l.map(c,d,j,f),f),u=l.map(e,d,j,t);return t?(r.input=l.digIn(s,t,e,!0),r.output=l.digIn(o,t,u,!0,(c,f,A,p)=>d(c(f&&l.copy(f)),p))):(r.input=e,r.output=u),g[""]&&(r.output=g[""].fit(r.output,o)),I(n)},I=n=>{let t=m(n),{output:e,flat:r,watch:s}=t,o=t.flat={},i=t.changes=[],g=(u,c)=>{u!==r[c]&&i.push(c),o[c]=u,delete r[c]},d=(u,c)=>{l.forEach(u,g,d,c),o[c]=u,delete r[c]};l.forEach(e,g,d);for(let u in r)!l.isMapable(r[u])&&o[u]!=r[u]&&i.push(u);if(!i.length)return i;let j=" ^"+i.join(" ^");for(let u in s)j.includes(" ^"+u)&&s[u].run(i);return i};var x=class{constructor(t=!1){Object.defineProperty(this,"debug",{enumerable:!0,value:Boolean.jet.to(t)}),F(this)}throw(t,e,r){throw`jet-base${t?` ${t}(...)`:""}${r?` path '${r}'`:""} ${e}`}is(t,e){return w(this,t)===e}isType(t,e,r){return _.is(e,w(this,t),r)}isFull(t){return _.isFull(w(this,t))}get(t,e){let r=w(this,t);return r!=null?_.copy(r,!0):e}getType(t,e=!1){return _(w(this,t),e)}set(t,e){e===void 0&&typeof t=="object"&&!Array.isArray(t)&&(e=t,t="");let r=new Date,s=y(this,t,e);return this.log("changes",new Date-r+"ms",s),s}remove(t){return y(this,t)}pull(t){let e=this.get(t);return this.remove(t),e}watch(t,e){return a(this,t,e)}fit(t,e){return b(this,t,e)}fitTo(t,e,...r){return this.fit(t,(s,o,i)=>_.to(e,s(o,i),...r))}fitType(t,e,...r){return this.fit(t,(s,o,i)=>_.tap(e,s(o,i),...r))}default(t,e,r=!1){let s=r?_.isFull:o=>o!=null;return this.fit(t,(o,i,g)=>s(o(i,g))?i:e)}lock(t,e){return this.fit(t,e===void 0?(r,s,o)=>o:r=>e)}log(...t){this.debug&&console.log("jet-base log",...t)}},O=x;export{O as default};
// src/index.js
import jet2 from "@randajan/jet-core";
// src/private.js
import jet from "@randajan/jet-core";
var LIST = /* @__PURE__ */ new Map();
var use = (base) => LIST.get(base);
var register = (base) => {
LIST.set(base, {
flat: {},
fit: {},
watch: {},
store: {}
});
};
var get = (base, path) => {
path = String.jet.to(path, ".");
return path ? use(base).flat[path] : use(base).output;
};
var formatDutyArgs = (path, fce) => {
if (fce === void 0 && jet.isRunnable(path)) {
fce = path;
path = "";
} else {
path = String.jet.to(path, ".");
}
return [path, fce];
};
var addDuty = (priv, kind, path, fce) => (priv[kind][path] = priv[kind][path] || jet.create.RunPool()).add(fce);
var filterChanges = (path, changes) => {
if (!path) {
return [...changes];
}
const result = [];
for (const c of changes) {
if (c.startsWith(path)) {
result.push(c.slice(path.length + 1));
}
}
return result;
};
var watch = (base, path, fce) => {
[path, fce] = formatDutyArgs(path, fce);
return addDuty(use(base), "watch", path, (cngs) => {
fce((p) => base.get([path, p]), (_) => filterChanges(path, cngs));
});
};
var fit = (base, path, fce) => {
[path, fce] = formatDutyArgs(path, fce);
const _p = use(base);
const rem = addDuty(_p, "fit", path, fce);
const refit = path ? (_) => set(base, path, jet.digOut(_p.input, path)) : (_) => set(base, path, _p.input);
refit();
return (_) => {
rem();
refit();
};
};
var set = (base, path, value) => {
const _p = use(base), { input, output, flat, fit: fit2 } = _p;
path = String.jet.to(path, ".");
const put = (v, p) => p && fit2[p] && fit2[p].fit ? fit2[p].fit(v, flat[p]) : v;
const deep = (v, p) => put(jet.map(v, put, deep, p), p);
let dummy = jet.map(value, put, deep, path);
if (!path) {
_p.input = value;
_p.output = dummy;
} else {
_p.input = jet.digIn(input, path, value, true);
_p.output = jet.digIn(output, path, dummy, true, (next, parent, path2, dir) => put(next(parent ? jet.copy(parent) : parent), dir));
}
if (fit2[""]) {
_p.output = fit2[""].fit(_p.output, output);
}
return flatIt(base);
};
var flatIt = (base) => {
const _p = use(base), { output, flat, watch: watch2 } = _p;
const newFlat = _p.flat = {};
const cngs = _p.changes = [];
const put = (v, p) => {
if (v !== flat[p]) {
cngs.push(p);
}
newFlat[p] = v;
delete flat[p];
};
const deep = (v, p) => {
jet.forEach(v, put, deep, p);
newFlat[p] = v;
delete flat[p];
};
jet.forEach(output, put, deep);
for (const p in flat) {
if (!jet.isMapable(flat[p]) && newFlat[p] != flat[p]) {
cngs.push(p);
}
}
if (!cngs.length) {
return cngs;
}
const c = " ^" + cngs.join(" ^");
for (const p in watch2) {
if (c.includes(" ^" + p)) {
watch2[p].run(cngs);
}
}
return cngs;
};
// src/index.js
var Base = class {
constructor(debug = false) {
Object.defineProperty(this, "debug", { enumerable: true, value: Boolean.jet.to(debug) });
register(this);
}
throw(method, msg, path) {
throw `jet-base${method ? ` ${method}(...)` : ""}${path ? ` path '${path}'` : ""} ${msg}`;
}
is(path, value) {
return get(this, path) === value;
}
isType(path, type, soft) {
return jet2.is(type, get(this, path), soft);
}
isFull(path) {
return jet2.isFull(get(this, path));
}
get(path, def) {
const v = get(this, path);
return v != null ? jet2.copy(v, true) : def;
}
getType(path, all = false) {
return jet2(get(this, path), all);
}
set(path, value) {
if (value === void 0 && typeof path === "object" && !Array.isArray(path)) {
value = path;
path = "";
}
const ms = new Date();
const changes = set(this, path, value);
this.log("changes", new Date() - ms + "ms", changes);
return changes;
}
remove(path) {
return set(this, path);
}
pull(path) {
const value = this.get(path);
this.remove(path);
return value;
}
watch(path, fce) {
return watch(this, path, fce);
}
fit(path, fce) {
return fit(this, path, fce);
}
fitTo(path, type, ...args) {
return this.fit(path, (next, v, f) => jet2.to(type, next(v, f), ...args));
}
fitType(path, type, ...args) {
return this.fit(path, (next, v, f) => jet2.tap(type, next(v, f), ...args));
}
default(path, value, force = false) {
const isFull = force ? jet2.isFull : (v) => v != null;
return this.fit(path, (next, v, f) => isFull(next(v, f)) ? v : value);
}
lock(path, value) {
return this.fit(path, value === void 0 ? (next, v, f) => f : (_) => value);
}
log(...msg) {
if (this.debug) {
console.log("jet-base log", ...msg);
}
}
};
var src_default = Base;
export {
src_default as default
};
//# sourceMappingURL=index.js.map

2

package.json
{
"name": "@randajan/jet-base",
"version": "1.1.0",
"version": "1.1.1",
"description": "Ecosystem of types and related usefull tools.",

@@ -5,0 +5,0 @@ "repository": "randajan/jet-base",

Sorry, the diff of this file is not supported yet

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