@openframe-org/criteria-set-protocol 1.4.6 → 1.4.7

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.
@@ -1,17 +1,33 @@
1
- import { Color, CriteriaTreeElement, Quality, Criterion, Task, TaskGroup, TaskItem } from './types';
1
+ import { Color, CriteriaTree, CriteriaTreeElement, Quality, Criterion, Task, TaskGroup, TaskItem } from './types';
2
2
  export declare const isQuality: (element: CriteriaTreeElement) => element is Quality;
3
3
  export declare const isCriterion: (element: CriteriaTreeElement) => element is Criterion;
4
4
  export declare const isTaskGroup: (element: CriteriaTreeElement) => element is TaskGroup;
5
5
  export declare const isTask: (element: CriteriaTreeElement) => element is Task;
6
6
  export declare const isTaskItem: (element: CriteriaTreeElement) => element is TaskItem;
7
+ /**
8
+ * Convert a color object to a hex string
9
+ */
7
10
  export declare const toColorHexString: (color: Color) => string;
11
+ /**
12
+ * Check if a tree element should be hidden in the output
13
+ */
8
14
  export declare const shouldHideCode: (element: CriteriaTreeElement | {
9
15
  code: string;
10
16
  } | string) => boolean;
17
+ /**
18
+ * Get the qualified name of a tree element, which is the title with the code prepended if it is different
19
+ */
11
20
  export declare const getQualifiedName: (element: Quality | Criterion | TaskGroup | Task | {
12
21
  code: string;
13
22
  title: string;
14
23
  }) => string;
24
+ /**
25
+ * Get the code for a tree element, stripping away unnecessary characters
26
+ */
15
27
  export declare const resolveCode: (element: CriteriaTreeElement | {
16
28
  code: string;
17
29
  } | string) => string;
30
+ /**
31
+ * Find an element in the criteria tree by its code
32
+ */
33
+ export declare const findInTree: (tree: CriteriaTree, code: string) => CriteriaTreeElement | null;
package/dist/v1/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveCode = exports.getQualifiedName = exports.shouldHideCode = exports.toColorHexString = exports.isTaskItem = exports.isTask = exports.isTaskGroup = exports.isCriterion = exports.isQuality = void 0;
3
+ exports.findInTree = exports.resolveCode = exports.getQualifiedName = exports.shouldHideCode = exports.toColorHexString = exports.isTaskItem = exports.isTask = exports.isTaskGroup = exports.isCriterion = exports.isQuality = void 0;
4
4
  const isQuality = (element) => element.type === 'quality';
5
5
  exports.isQuality = isQuality;
6
6
  const isCriterion = (element) => element.type === 'criterion';
@@ -11,6 +11,9 @@ const isTask = (element) => element.type === 'task';
11
11
  exports.isTask = isTask;
12
12
  const isTaskItem = (element) => element.type === 'task-item';
13
13
  exports.isTaskItem = isTaskItem;
14
+ /**
15
+ * Convert a color object to a hex string
16
+ */
14
17
  const toColorHexString = (color) => {
15
18
  if (typeof color === 'string') {
16
19
  return color;
@@ -18,10 +21,16 @@ const toColorHexString = (color) => {
18
21
  return `#${color.red.toString(16)}${color.green.toString(16)}${color.blue.toString(16)}`;
19
22
  };
20
23
  exports.toColorHexString = toColorHexString;
24
+ /**
25
+ * Check if a tree element should be hidden in the output
26
+ */
21
27
  const shouldHideCode = (element) => {
22
28
  return (typeof element === 'string' ? element : element.code).startsWith('_');
23
29
  };
24
30
  exports.shouldHideCode = shouldHideCode;
31
+ /**
32
+ * Get the qualified name of a tree element, which is the title with the code prepended if it is different
33
+ */
25
34
  const getQualifiedName = (element) => {
26
35
  const code = element.code.startsWith('_') ? element.code.substring(1) : element.code;
27
36
  if (element.title === code) {
@@ -30,8 +39,43 @@ const getQualifiedName = (element) => {
30
39
  return `${code} ${element.title}`;
31
40
  };
32
41
  exports.getQualifiedName = getQualifiedName;
42
+ /**
43
+ * Get the code for a tree element, stripping away unnecessary characters
44
+ */
33
45
  const resolveCode = (element) => {
34
46
  const resolvedCode = typeof element === 'string' ? element : element.code;
35
47
  return resolvedCode.startsWith('_') ? resolvedCode.substring(1) : resolvedCode;
36
48
  };
37
49
  exports.resolveCode = resolveCode;
50
+ /**
51
+ * Find an element in the criteria tree by its code
52
+ */
53
+ const findInTree = (tree, code) => {
54
+ for (const quality of tree.qualities) {
55
+ if (quality.code === code) {
56
+ return quality;
57
+ }
58
+ for (const criteria of quality.items) {
59
+ if (criteria.code === code) {
60
+ return criteria;
61
+ }
62
+ for (const taskGroup of criteria.items) {
63
+ if (taskGroup.code === code) {
64
+ return taskGroup;
65
+ }
66
+ for (const task of taskGroup.items) {
67
+ if (task.code === code) {
68
+ return task;
69
+ }
70
+ for (const taskItem of task.items) {
71
+ if (taskItem.code === code) {
72
+ return taskItem;
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
79
+ return null;
80
+ };
81
+ exports.findInTree = findInTree;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openframe-org/criteria-set-protocol",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "A protocol and tools for defining and working with criteria sets",
5
5
  "private": false,
6
6
  "author": "Andrés Angulo <aa@openframe.org>",