pacc 3.0.0 → 3.1.1

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/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)
@@ -34,8 +35,12 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
34
35
  * [Parameters](#parameters-1)
35
36
  * [getAttributeAndOperator](#getattributeandoperator)
36
37
  * [Parameters](#parameters-2)
37
- * [tokens](#tokens)
38
+ * [Token](#token)
39
+ * [Properties](#properties-1)
40
+ * [createToken](#createtoken)
38
41
  * [Parameters](#parameters-3)
42
+ * [tokens](#tokens)
43
+ * [Parameters](#parameters-4)
39
44
 
40
45
  ## AttributeDefinition
41
46
 
@@ -86,9 +91,24 @@ The name may be a property path like 'a.b.c <='.
86
91
 
87
92
  * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
88
93
  * `expression` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
89
- * `getters` (optional, default `{}`)
90
94
 
91
- Returns **\[any, [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)]** value associated with the given property name
95
+ Returns **\[any, [Token](#token)]** value associated with the given property name
96
+
97
+ ## Token
98
+
99
+ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
100
+
101
+ ### Properties
102
+
103
+ * `str` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
104
+
105
+ ## createToken
106
+
107
+ ### Parameters
108
+
109
+ * `str` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
110
+
111
+ Returns **[Token](#token)**&#x20;
92
112
 
93
113
  ## tokens
94
114
 
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
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
35
  "ava": "^6.1.1",
29
- "browser-ava": "^2.1.9",
36
+ "browser-ava": "^2.2.0",
30
37
  "c8": "^9.1.0",
31
38
  "documentation": "^14.0.3",
32
- "semantic-release": "^23.0.0"
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
@@ -13,6 +13,11 @@
13
13
  * @property {string[]|string} [env] environment variable use to provide the value
14
14
  */
15
15
 
16
+ /**
17
+ * @typedef {Object} Token
18
+ * @property {string} str
19
+ */
20
+
16
21
  import {
17
22
  tokens,
18
23
  EQUAL,
@@ -83,7 +88,7 @@ export function getAttribute(object, expression) {
83
88
  * The name may be a property path like 'a.b.c <='.
84
89
  * @param {Object} object
85
90
  * @param {string} expression
86
- * @returns {[any,string]} value associated with the given property name
91
+ * @returns {[any,Token]} value associated with the given property name
87
92
  */
88
93
  export function getAttributeAndOperator(object, expression) {
89
94
  let op = EQUAL;
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;
@@ -221,6 +231,7 @@ export function* tokens(string) {
221
231
  state = "number";
222
232
  break;
223
233
  case "number":
234
+ // @ts-ignore
224
235
  buffer = buffer * 10 + c.charCodeAt(0) - 48;
225
236
  break;
226
237
  case "string":
@@ -0,0 +1,61 @@
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
+ };
59
+ export type Token = {
60
+ str: string;
61
+ };
@@ -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
+ };