@gershy/util-jsfn-encode 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cmp/cjs/main.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import '../sideEffects.js';
2
1
  import '@gershy/clearing';
3
2
  export type JsImport = {
4
3
  varDef: null | string;
package/cmp/cjs/main.js CHANGED
@@ -1,46 +1,56 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- require("@gershy/clearing");
4
- exports.default = (args) => {
5
- // const importReg = niceRegex(String[cl.baseline](`
6
- // | ^[ ]* (?: )?
7
- // | const[ ] [=][ ]* [.]jsfnImport[(]['#] ['#][)] [ ]+as[ ]
8
- // | ([^=]+) [a-zA-Z][a-zA-Z0-9.]* ([^'#]+)
9
- // `).replaceAll('#', '`'));
10
- // Captures lines like:
11
- // const util = ctx.jsfnImport('<repo>/src/boot/util');
12
- // const util = ctx.jsfnImport('<repo>/src/boot/util') as typeof import('../src/boot/util');
13
- // const { util1, util2 } = ctx.jsfnImport('<repo>/src/boot/util') as typeof import('../src/boot/util');
14
- // const { util1, util2 } = c.jsfnImport('<repo>/src/boot/util') as typeof import('../src/boot/util');
15
- const jsImports = []; // Note "js imports" are a "reference to code, including a url, relative filepath, or name of an npm module"
16
- const serializeObjKey = (key) => /^[$_a-zA-Z][$_a-zA-Z]+$/.test(key) ? key : `'${key.replaceAll(`'`, `\\'`)}'`;
17
- const serialize = (val) => {
18
- if (cl.isCls(val, Array))
19
- return '[' + val.map((v) => serialize(v)).join(',') + ']';
20
- if (cl.isCls(val, Object))
21
- return '{' + val[cl.toArr]((v, k) => `${serializeObjKey(k)}:${serialize(v)}`).join(',') + '}';
22
- if (cl.inCls(val, Function)) {
23
- const importReg = /\b(?:const|let|var)[ ]*([^=]+)[=][ ]*[a-zA-Z][a-zA-Z0-9.]*[.]jsfnImport[(]["'`]([^"'`]+)["'`][)][;]?/g;
24
- return val.toString().replace(importReg, (full, varDef, importPath) => {
25
- jsImports.push({ varDef, importPath });
26
- return `/*jsfn:hoisted:${full}*/`;
27
- });
28
- }
29
- if (cl.inCls(val?.toJsfn, Function)) {
30
- const { args, form, hoist } = val;
31
- const [importPath, clsName] = hoist.split('::');
32
- jsImports.push({ varDef: clsName, importPath });
33
- return `new ${clsName}(${args.map(a => serialize(a)).join(',')})`;
34
- }
35
- return JSON.stringify(val);
36
- };
37
- return {
38
- // Note `code` is stringified, but it isn't json - it's js, in string representation
39
- code: serialize(args.val), // `jsImports` isn't populated until this is called!
40
- // Imports beginning with "." are treated as relative paths
41
- jsImports: jsImports.map(ji => ji.importPath[0] !== '.' ? ji : {
42
- ...ji,
43
- importPath: new URL(ji.importPath, args.baseUrl).href
44
- })
45
- };
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var main_exports = {};
20
+ __export(main_exports, {
21
+ default: () => main_default
22
+ });
23
+ module.exports = __toCommonJS(main_exports);
24
+ var import_clearing = require("@gershy/clearing");
25
+ var main_default = (args) => {
26
+ const jsImports = [];
27
+ const serializeObjKey = (key) => /^[$_a-zA-Z][$_a-zA-Z]+$/.test(key) ? key : `'${key.replaceAll(`'`, `\\'`)}'`;
28
+ const serialize = (val) => {
29
+ if (cl.isCls(val, Array)) return "[" + val.map((v) => serialize(v)).join(",") + "]";
30
+ if (cl.isCls(val, Object)) return "{" + val[cl.toArr]((v, k) => `${serializeObjKey(k)}:${serialize(v)}`).join(",") + "}";
31
+ if (cl.inCls(val, Function)) {
32
+ const importReg = /\b(?:const|let|var)[ ]*([^=]+)[=][ ]*[a-zA-Z][a-zA-Z0-9.]*[.]jsfnImport[(]["'`]([^"'`]+)["'`][)][;]?/g;
33
+ return val.toString().replace(importReg, (full, varDef, importPath) => {
34
+ jsImports.push({ varDef, importPath });
35
+ return `/*jsfn:hoisted:${full}*/`;
36
+ });
37
+ }
38
+ if (cl.inCls(val?.toJsfn, Function)) {
39
+ const { args: args2, hoist } = val;
40
+ const [importPath, clsName] = hoist.split("::");
41
+ jsImports.push({ varDef: clsName, importPath });
42
+ return `new ${clsName}(${args2.map((a) => serialize(a)).join(",")})`;
43
+ }
44
+ return JSON.stringify(val);
45
+ };
46
+ return {
47
+ // Note `code` is stringified, but it isn't json - it's js, in string representation
48
+ code: serialize(args.val),
49
+ // `jsImports` isn't populated until this is called!
50
+ // Imports beginning with "." are treated as relative paths
51
+ jsImports: jsImports.map((ji) => ji.importPath[0] !== "." ? ji : {
52
+ ...ji,
53
+ importPath: new URL(ji.importPath, args.baseUrl).href
54
+ })
55
+ };
46
56
  };
@@ -1,4 +1,3 @@
1
- import '../sideEffects.js';
2
1
  import '@gershy/clearing';
3
2
  export type JsImport = {
4
3
  varDef: null | string;
@@ -0,0 +1,36 @@
1
+ import "@gershy/clearing";
2
+ var main_default = (args) => {
3
+ const jsImports = [];
4
+ const serializeObjKey = (key) => /^[$_a-zA-Z][$_a-zA-Z]+$/.test(key) ? key : `'${key.replaceAll(`'`, `\\'`)}'`;
5
+ const serialize = (val) => {
6
+ if (cl.isCls(val, Array)) return "[" + val.map((v) => serialize(v)).join(",") + "]";
7
+ if (cl.isCls(val, Object)) return "{" + val[cl.toArr]((v, k) => `${serializeObjKey(k)}:${serialize(v)}`).join(",") + "}";
8
+ if (cl.inCls(val, Function)) {
9
+ const importReg = /\b(?:const|let|var)[ ]*([^=]+)[=][ ]*[a-zA-Z][a-zA-Z0-9.]*[.]jsfnImport[(]["'`]([^"'`]+)["'`][)][;]?/g;
10
+ return val.toString().replace(importReg, (full, varDef, importPath) => {
11
+ jsImports.push({ varDef, importPath });
12
+ return `/*jsfn:hoisted:${full}*/`;
13
+ });
14
+ }
15
+ if (cl.inCls(val?.toJsfn, Function)) {
16
+ const { args: args2, hoist } = val;
17
+ const [importPath, clsName] = hoist.split("::");
18
+ jsImports.push({ varDef: clsName, importPath });
19
+ return `new ${clsName}(${args2.map((a) => serialize(a)).join(",")})`;
20
+ }
21
+ return JSON.stringify(val);
22
+ };
23
+ return {
24
+ // Note `code` is stringified, but it isn't json - it's js, in string representation
25
+ code: serialize(args.val),
26
+ // `jsImports` isn't populated until this is called!
27
+ // Imports beginning with "." are treated as relative paths
28
+ jsImports: jsImports.map((ji) => ji.importPath[0] !== "." ? ji : {
29
+ ...ji,
30
+ importPath: new URL(ji.importPath, args.baseUrl).href
31
+ })
32
+ };
33
+ };
34
+ export {
35
+ main_default as default
36
+ };
@@ -0,0 +1,2 @@
1
+ declare global {}
2
+ export {};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@gershy/util-jsfn-encode",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
+ "author": "Gershom Maes",
4
5
  "description": "TODO",
5
6
  "keywords": [
6
7
  "TODO"
7
8
  ],
8
- "author": "Gershom Maes",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/gershyNpm/utilJsfnEncode.git"
@@ -14,36 +14,26 @@
14
14
  "url": "https://github.com/gershyNpm/utilJsfnEncode/issues"
15
15
  },
16
16
  "homepage": "https://github.com/gershyNpm/utilJsfnEncode#readme",
17
+ "type": "module",
18
+ "files": [
19
+ "cmp"
20
+ ],
17
21
  "license": "ISC",
18
22
  "peerDependencies": {
19
- "@gershy/clearing": "^0.0.36"
23
+ "@gershy/clearing": "^0.0.42"
20
24
  },
21
25
  "devDependencies": {
22
- "@types/node": "^24.10.1",
23
- "tsx": "^4.21.0",
24
- "typescript": "^5.9.3"
26
+ "@types/node": "^24.10.1"
25
27
  },
26
28
  "dependencies": {},
27
- "type": "module",
28
- "files": [
29
- "cmp"
30
- ],
31
- "sideEffects": false,
32
- "types": "./cmp/mjs/main.d.ts",
33
29
  "exports": {
34
30
  ".": {
35
- "import": "./cmp/mjs/main.js",
31
+ "import": "./cmp/esm/main.js",
36
32
  "require": "./cmp/cjs/main.js"
37
33
  }
38
34
  },
39
35
  "scripts": {
40
36
  "test": "npm run ts.check && npx tsx ./src/main.test.ts",
41
- "ts.check": "npx tsc --noEmit",
42
- "build.cjs": "tsc -p build/tsconfig.cjs.json",
43
- "build.mjs": "tsc -p build/tsconfig.mjs.json",
44
- "build": "node ./build/act.js removeCmp && npm run build.cjs && npm run build.mjs && node ./build/act.js finalizeExportVariants",
45
- "git.pub": "npm run test && git add --all && git commit -m \"automated\" && git push",
46
- "npm.login": "npm login",
47
- "npm.pub": "npm run test && npm run build && npm publish --access public"
37
+ "ts.check": "npx tsc --noEmit"
48
38
  }
49
39
  }
package/cmp/mjs/main.js DELETED
@@ -1,44 +0,0 @@
1
- import '@gershy/clearing';
2
- export default (args) => {
3
- // const importReg = niceRegex(String[cl.baseline](`
4
- // | ^[ ]* (?: )?
5
- // | const[ ] [=][ ]* [.]jsfnImport[(]['#] ['#][)] [ ]+as[ ]
6
- // | ([^=]+) [a-zA-Z][a-zA-Z0-9.]* ([^'#]+)
7
- // `).replaceAll('#', '`'));
8
- // Captures lines like:
9
- // const util = ctx.jsfnImport('<repo>/src/boot/util');
10
- // const util = ctx.jsfnImport('<repo>/src/boot/util') as typeof import('../src/boot/util');
11
- // const { util1, util2 } = ctx.jsfnImport('<repo>/src/boot/util') as typeof import('../src/boot/util');
12
- // const { util1, util2 } = c.jsfnImport('<repo>/src/boot/util') as typeof import('../src/boot/util');
13
- const jsImports = []; // Note "js imports" are a "reference to code, including a url, relative filepath, or name of an npm module"
14
- const serializeObjKey = (key) => /^[$_a-zA-Z][$_a-zA-Z]+$/.test(key) ? key : `'${key.replaceAll(`'`, `\\'`)}'`;
15
- const serialize = (val) => {
16
- if (cl.isCls(val, Array))
17
- return '[' + val.map((v) => serialize(v)).join(',') + ']';
18
- if (cl.isCls(val, Object))
19
- return '{' + val[cl.toArr]((v, k) => `${serializeObjKey(k)}:${serialize(v)}`).join(',') + '}';
20
- if (cl.inCls(val, Function)) {
21
- const importReg = /\b(?:const|let|var)[ ]*([^=]+)[=][ ]*[a-zA-Z][a-zA-Z0-9.]*[.]jsfnImport[(]["'`]([^"'`]+)["'`][)][;]?/g;
22
- return val.toString().replace(importReg, (full, varDef, importPath) => {
23
- jsImports.push({ varDef, importPath });
24
- return `/*jsfn:hoisted:${full}*/`;
25
- });
26
- }
27
- if (cl.inCls(val?.toJsfn, Function)) {
28
- const { args, form, hoist } = val;
29
- const [importPath, clsName] = hoist.split('::');
30
- jsImports.push({ varDef: clsName, importPath });
31
- return `new ${clsName}(${args.map(a => serialize(a)).join(',')})`;
32
- }
33
- return JSON.stringify(val);
34
- };
35
- return {
36
- // Note `code` is stringified, but it isn't json - it's js, in string representation
37
- code: serialize(args.val), // `jsImports` isn't populated until this is called!
38
- // Imports beginning with "." are treated as relative paths
39
- jsImports: jsImports.map(ji => ji.importPath[0] !== '.' ? ji : {
40
- ...ji,
41
- importPath: new URL(ji.importPath, args.baseUrl).href
42
- })
43
- };
44
- };
File without changes
File without changes