pacc 2.1.5 → 3.1.0

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2023 by pacc
1
+ Copyright (c) 2023-2024 by pacc
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
package/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![npm](https://img.shields.io/npm/v/pacc.svg)](https://www.npmjs.com/package/pacc)
2
2
  [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
3
+ [![Typed with TypeScript](https://flat.badgen.net/badge/icon/Typed?icon=typescript\&label\&labelColor=blue\&color=555555)](https://typescriptlang.org)
3
4
  [![bundlejs](https://deno.bundlejs.com/?q=pacc\&badge=detailed)](https://bundlejs.com/?q=pacc)
4
5
  [![downloads](http://img.shields.io/npm/dm/pacc.svg?style=flat-square)](https://npmjs.org/package/pacc)
5
6
  [![GitHub Issues](https://img.shields.io/github/issues/arlac77/pacc.svg?style=flat-square)](https://github.com/arlac77/pacc/issues)
@@ -86,7 +87,6 @@ The name may be a property path like 'a.b.c <='.
86
87
 
87
88
  * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
88
89
  * `expression` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
89
- * `getters` (optional, default `{}`)
90
90
 
91
91
  Returns **\[any, [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)]** value associated with the given property name
92
92
 
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "2.1.5",
3
+ "version": "3.1.0",
4
4
  "publishConfig": {
5
- "access": "public"
5
+ "access": "public",
6
+ "provenance": true
6
7
  },
8
+ "types": "./types/attribute.d.mts",
7
9
  "exports": {
8
- ".": "./src/attribute.mjs"
10
+ ".": {
11
+ "types": "./types/attribute.d.mts",
12
+ "default": "./src/attribute.mjs"
13
+ }
9
14
  },
10
15
  "description": "property path utils",
11
16
  "contributors": [
@@ -16,24 +21,30 @@
16
21
  ],
17
22
  "license": "BSD-2-Clause",
18
23
  "scripts": {
24
+ "prepare": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs",
19
25
  "test": "npm run test:browser-ava && npm run test:ava",
20
26
  "test:browser-ava": "browser-ava --headless --no-keep-open tests/*-ava.mjs tests/*-ava-browser.mjs",
21
27
  "test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
22
28
  "cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
23
29
  "docs": "documentation readme --section=API ./src/**/*.mjs",
24
- "lint": "npm run lint:docs",
25
- "lint:docs": "documentation lint ./src/**/*.mjs"
30
+ "lint": "npm run lint:docs && npm run lint:tsc",
31
+ "lint:docs": "documentation lint ./src/**/*.mjs",
32
+ "lint:tsc": "tsc --allowJs --checkJs --noEmit -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
26
33
  },
27
34
  "devDependencies": {
28
- "ava": "^6.0.1",
29
- "browser-ava": "^2.1.6",
30
- "c8": "^8.0.1",
31
- "documentation": "^14.0.2",
32
- "semantic-release": "^22.0.12"
35
+ "ava": "^6.1.1",
36
+ "browser-ava": "^2.2.0",
37
+ "c8": "^9.1.0",
38
+ "documentation": "^14.0.3",
39
+ "semantic-release": "^23.0.2",
40
+ "typescript": "^5.3.3"
41
+ },
42
+ "engines": {
43
+ "node": ">=20.11.0"
33
44
  },
34
45
  "repository": {
35
46
  "type": "git",
36
- "url": "https://github.com/arlac77/pacc"
47
+ "url": "git+https://github.com/arlac77/pacc.git"
37
48
  },
38
49
  "bugs": {
39
50
  "url": "https://github.com/arlac77/pacc/issues"
@@ -43,7 +54,9 @@
43
54
  "inheritFrom": [
44
55
  "arlac77/template-arlac77-github",
45
56
  "arlac77/template-browser-ava",
46
- "arlac77/template-esm-only"
57
+ "arlac77/template-javascript-component",
58
+ "arlac77/template-node-component",
59
+ "arlac77/template-typescript"
47
60
  ]
48
61
  }
49
62
  }
package/src/attribute.mjs CHANGED
@@ -47,7 +47,7 @@ export function setAttribute(object, expression, value) {
47
47
 
48
48
  default:
49
49
  if (anchor) {
50
- anchor[anchorKey] = object = (typeof token === "string" ? {} : []);
50
+ anchor[anchorKey] = object = typeof token === "string" ? {} : [];
51
51
  anchor = undefined;
52
52
  }
53
53
 
@@ -83,9 +83,9 @@ export function getAttribute(object, expression) {
83
83
  * The name may be a property path like 'a.b.c <='.
84
84
  * @param {Object} object
85
85
  * @param {string} expression
86
- * @returns {[any,string]} value associated with the given property name
86
+ * @returns {[any,Token]} value associated with the given property name
87
87
  */
88
- export function getAttributeAndOperator(object, expression, getters = {}) {
88
+ export function getAttributeAndOperator(object, expression) {
89
89
  let op = EQUAL;
90
90
  let predicateTokens;
91
91
 
@@ -120,15 +120,10 @@ export function getAttributeAndOperator(object, expression, getters = {}) {
120
120
  break;
121
121
  }
122
122
 
123
- const g = getters[token];
124
- if (g) {
125
- object = g(object);
123
+ if (object[token] !== undefined) {
124
+ object = object[token];
126
125
  } else {
127
- if (object[token] !== undefined) {
128
- object = object[token];
129
- } else {
130
- return [undefined, op];
131
- }
126
+ return [undefined, op];
132
127
  }
133
128
  }
134
129
  }
package/src/tokens.mjs CHANGED
@@ -1,5 +1,15 @@
1
1
  const lookup = {};
2
2
 
3
+ /**
4
+ * @typedef {Object} Token
5
+ * @property {string} str
6
+ */
7
+
8
+ /**
9
+ *
10
+ * @param {string} str
11
+ * @returns {Token}
12
+ */
3
13
  function createToken(str) {
4
14
  const token = { str };
5
15
  lookup[str] = token;
@@ -37,7 +47,7 @@ export const DOUBLE_BAR = createToken("||");
37
47
  * Split property path into tokens
38
48
  * @generator
39
49
  * @param {string} string
40
- * @yields {string}
50
+ * @yields {Token}
41
51
  */
42
52
  export function* tokens(string) {
43
53
  let state, buffer, hex;
@@ -217,11 +227,11 @@ export function* tokens(string) {
217
227
  default:
218
228
  yield lookup[state];
219
229
  case undefined:
220
- buffer = c.charCodeAt(0) - "0".charCodeAt(0);
230
+ buffer = c.charCodeAt(0) - 48;
221
231
  state = "number";
222
232
  break;
223
233
  case "number":
224
- buffer = buffer * 10 + c.charCodeAt(0) - "0".charCodeAt(0);
234
+ buffer = buffer * 10 + c.charCodeAt(0) - 48;
225
235
  break;
226
236
  case "string":
227
237
  case "identifier":
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Set Object attribute.
3
+ * The name may be a property path like 'a.b.c'.
4
+ * @param {Object} object
5
+ * @param {string} expression
6
+ * @param {any} value
7
+ */
8
+ export function setAttribute(object: any, expression: string, value: any): void;
9
+ /**
10
+ * Deliver attribute value.
11
+ * The name may be a property path like 'a.b.c' or a[2]
12
+ * @param {Object} object
13
+ * @param {string} expression
14
+ * @returns {any} value associated with the given property name
15
+ */
16
+ export function getAttribute(object: any, expression: string): any;
17
+ /**
18
+ * Deliver attribute value and operator.
19
+ * The name may be a property path like 'a.b.c <='.
20
+ * @param {Object} object
21
+ * @param {string} expression
22
+ * @returns {[any,Token]} value associated with the given property name
23
+ */
24
+ export function getAttributeAndOperator(object: any, expression: string): [any, Token];
25
+ export * from "./tokens.mjs";
26
+ export type AttributeDefinition = {
27
+ type: string;
28
+ writable: boolean;
29
+ /**
30
+ * should the value be shown
31
+ */
32
+ private?: boolean;
33
+ /**
34
+ * name of an attribute we depend on
35
+ */
36
+ depends?: string;
37
+ /**
38
+ * extra attributes that are present in case our attribute is set
39
+ */
40
+ additionalAttributes: string[];
41
+ description: string;
42
+ /**
43
+ * the default value
44
+ */
45
+ default?: any;
46
+ /**
47
+ * set the value
48
+ */
49
+ set?: Function;
50
+ /**
51
+ * get the value can be used to calculate default values
52
+ */
53
+ get?: Function;
54
+ /**
55
+ * environment variable use to provide the value
56
+ */
57
+ env?: string[] | string;
58
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Split property path into tokens
3
+ * @generator
4
+ * @param {string} string
5
+ * @yields {Token}
6
+ */
7
+ export function tokens(string: string): Generator<any, void, unknown>;
8
+ export namespace PLUS {
9
+ let str: string;
10
+ }
11
+ export namespace MINUS { }
12
+ export namespace STAR { }
13
+ export namespace DIVIDE { }
14
+ export namespace NOT { }
15
+ export namespace NOT_EQUAL { }
16
+ export namespace GREATER { }
17
+ export namespace GREATER_EQUAL { }
18
+ export namespace LESS { }
19
+ export namespace LESS_EQUAL { }
20
+ export namespace EQUAL { }
21
+ export namespace OPEN_ROUND { }
22
+ export namespace CLOSE_ROUND { }
23
+ export namespace OPEN_BRACKET { }
24
+ export namespace CLOSE_BRACKET { }
25
+ export namespace OPEN_CURLY { }
26
+ export namespace CLOSE_CURLY { }
27
+ export namespace QUESTION { }
28
+ export namespace COLON { }
29
+ export namespace SEMICOLON { }
30
+ export namespace COMMA { }
31
+ export namespace DOT { }
32
+ export namespace AMPERSAND { }
33
+ export namespace DOUBLE_AMPERSAND { }
34
+ export namespace BAR { }
35
+ export namespace DOUBLE_BAR { }
36
+ export type Token = {
37
+ str: string;
38
+ };