@ygracs/xepg-lib-js 0.0.23 → 0.0.25

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.
@@ -0,0 +1,133 @@
1
+ // [v0.1.002-20250825]
2
+
3
+ // === module init block ===
4
+
5
+ const {
6
+ //valueToIndex,
7
+ valueToIDString,
8
+ //readAsString, readAsNumber,
9
+ //isNotEmptyString,
10
+ //isArray, isObject, isPlainObject,
11
+ } = require('@ygracs/bsfoc-lib-js');
12
+
13
+ // === module inner block ===
14
+
15
+ /***
16
+ * (* helper function definitions *)
17
+ */
18
+
19
+ // === module main block ===
20
+
21
+ /***
22
+ * (* constant definitions *)
23
+ */
24
+
25
+ /***
26
+ * (* function definitions *)
27
+ */
28
+
29
+ /**
30
+ * Tries to convert a given value to a valid tag name of an XML-element.
31
+ * @since v0.0.23
32
+ * @function readAsTagName
33
+ * @param {any} value - some value
34
+ * @returns {string}
35
+ */
36
+ function readAsTagName(value) {
37
+ let tagName = valueToIDString(value, { ignoreNumbers: true });
38
+ if (tagName === null) return '';
39
+ if (tagName !== '') {
40
+ // // TODO: do extra checks
41
+ const template = /[\s\/\\\"\'<>=]/;
42
+ const trigger = tagName.match(template);
43
+ if (trigger) {
44
+ //console.log(trigger);
45
+ tagName = '';
46
+ };
47
+ };
48
+ return tagName;
49
+ };
50
+
51
+ /**
52
+ * Tries to convert a given value to a valid name of an XML-attribute.
53
+ * @since v0.0.23
54
+ * @function readAsAttrName
55
+ * @param {any} value - some value
56
+ * @returns {string}
57
+ */
58
+ function readAsAttrName(value) {
59
+ let attrName = valueToIDString(value, { ignoreNumbers: true });
60
+ if (attrName === null) return '';
61
+ if (attrName !== '') {
62
+ // // TODO: do extra checks
63
+ const template = /[\s\/\\\"\'<>=]/;
64
+ const trigger = attrName.match(template);
65
+ if (trigger) {
66
+ //console.log(trigger);
67
+ attrName = '';
68
+ };
69
+ };
70
+ return attrName;
71
+ };
72
+
73
+ /**
74
+ * Tries to convert a given value to a valid "attribute value".
75
+ * @since v0.0.25
76
+ * @function readAsAttrValue
77
+ * @param {any} value - some value
78
+ * @return {?string}
79
+ */
80
+ function readAsAttrValue(value) {
81
+ let result = null;
82
+ switch (typeof value) {
83
+ case 'boolean': {
84
+ result = value.toString();
85
+ break;
86
+ }
87
+ case 'number': {
88
+ if (Number.isNaN(value)) break;
89
+ result = value.toString();
90
+ break;
91
+ }
92
+ case 'string': {
93
+ result = value.trim();
94
+ break;
95
+ }
96
+ default: {}
97
+ };
98
+ return result;
99
+ };
100
+
101
+ /**
102
+ * Tries to convert a given value to a valid identifier suitable as a value
103
+ * for an "ID-attribute" of an XML-element.
104
+ * @since v0.0.23
105
+ * @function valueToElementID
106
+ * @param {any} value - some value
107
+ * @returns {string}
108
+ */
109
+ function valueToElementID(value) {
110
+ let id = valueToIDString(value);
111
+ if (id === null) return '';
112
+ if (id !== '') {
113
+ // // TODO: do extra checks
114
+ const template = /[\s\/\\\"\'<>=]/;
115
+ const trigger = id.match(template);
116
+ if (trigger) {
117
+ //console.log(trigger);
118
+ id = '';
119
+ };
120
+ };
121
+ return id;
122
+ };
123
+
124
+ /***
125
+ * (* class definitions *)
126
+ */
127
+
128
+ // === module exports block ===
129
+
130
+ module.exports.readAsTagName = readAsTagName;
131
+ module.exports.readAsAttrName = readAsAttrName;
132
+ module.exports.readAsAttrValue = readAsAttrValue;
133
+ module.exports.valueToElementID = valueToElementID;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ygracs/xepg-lib-js",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "A library for handling an EPG-sources based on an XEPG-format",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -19,6 +19,7 @@
19
19
  "doc/*.md",
20
20
  "lib/xepgdoc-lib.js",
21
21
  "lib/dts-helper.js",
22
+ "lib/xml-base.js",
22
23
  "index.js",
23
24
  "CHANGELOG.md"
24
25
  ],
@@ -33,15 +34,15 @@
33
34
  },
34
35
  "dependencies": {
35
36
  "@cntwg/file-helper": "^0.0.1",
36
- "@ygracs/bsfoc-lib-js": "^0.2.3",
37
- "@ygracs/dtf-lib-js": "^0.0.28",
37
+ "@ygracs/bsfoc-lib-js": "^0.3.0",
38
+ "@ygracs/dtf-lib-js": "^0.0.30",
38
39
  "@ygracs/xml-js6": "^0.0.5-b",
39
- "@ygracs/xobj-lib-js": "^0.2.2"
40
+ "@ygracs/xobj-lib-js": "^0.2.4"
40
41
  },
41
42
  "devDependencies": {
42
- "cross-env": "^7.0.3",
43
- "jest": "^29.7.0",
44
- "jsdoc-to-markdown": "^9.1.1",
43
+ "cross-env": "^10.0.0",
44
+ "jest": "^30.0.5",
45
+ "jsdoc-to-markdown": "^9.1.2",
45
46
  "minimist": "^1.2.8"
46
47
  }
47
48
  }