@cntwg/html-helper 0.0.19 → 0.0.20

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ #### *v0.0.20*
2
+
3
+ Pre-release version.
4
+
5
+ > - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.4;
6
+ > - some fixes in `html-helper-lib.js` module.
7
+
1
8
  #### *v0.0.19*
2
9
 
3
10
  Pre-release version.
@@ -1,10 +1,11 @@
1
- // [v0.1.019-20230614]
1
+ // [v0.1.020-20230801]
2
2
 
3
3
  // === module init block ===
4
4
 
5
5
  const {
6
6
  readAsString,
7
7
  isArray, isObject, isPlainObject, valueToArray,
8
+ valueToIDString,
8
9
  } = require('@ygracs/bsfoc-lib-js');
9
10
 
10
11
  const CSS_CLASS_CURRENT = 'current';
@@ -177,26 +178,6 @@ function valueToClassList(value, opt){
177
178
  return result;
178
179
  };
179
180
 
180
- function valueToIDString(value){
181
- let result = '';
182
- switch (typeof value) {
183
- case 'number': {
184
- if (Number.isNaN(value) || value < 0) break;
185
- if (Number.isInteger(value)) result = value.toString();
186
- break;
187
- }
188
- case 'string': {
189
- result = value.trim();
190
- // // TODO: check if a valid character sequencies
191
- break;
192
- }
193
- default: {
194
- break;
195
- }
196
- };
197
- return result;
198
- };
199
-
200
181
  function createNewHtmlElement(tagName, opt){
201
182
  let _tag = typeof tagName === 'string' ? tagName.trim() : '';
202
183
  if (_tag === '') return null;
@@ -211,7 +192,7 @@ function createNewHtmlElement(tagName, opt){
211
192
  data: dset,
212
193
  } = opt;
213
194
  // set an element id
214
- if ((id = valueToIDString(id)) !== '') item.setAttribute('id', id);
195
+ if ((id = valueToIDString(id)) !== null) item.setAttribute('id', id);
215
196
  // set an element text context
216
197
  if (typeof text === 'string') {
217
198
  item.appendChild(document.createTextNode(text));
@@ -220,15 +201,12 @@ function createNewHtmlElement(tagName, opt){
220
201
  if (isObject(attr)) {
221
202
  attr = isArray(attr) ? attr : Object.entries(attr);
222
203
  for (let [ key, value ] of attr ) {
223
- key = (typeof key === 'string') ? key.trim() : '';
224
- if (key !== '') {
225
- value = readAsString(value, '', {
226
- useTrim: true,
227
- numberToString: true,
228
- boolToString: true,
229
- });
230
- if (value !== '') item.setAttribute(key.toLowerCase(), value);
231
- }
204
+ if (
205
+ ((key = valueToIDString(key)) !== null)
206
+ && ((value = readAsAttrValue(value)) !== null)
207
+ ) {
208
+ item.setAttribute(key.toLowerCase(), value);
209
+ };
232
210
  };
233
211
  };
234
212
  // set a class-attributes of the element
@@ -241,15 +219,12 @@ function createNewHtmlElement(tagName, opt){
241
219
  if (isObject(dset)) {
242
220
  dset = isArray(dset) ? dset : Object.entries(dset);
243
221
  for (let [ key, value ] of dset ) {
244
- key = (typeof key === 'string') ? key.trim() : '';
245
- if (key !== '') {
246
- value = readAsString(value, '', {
247
- useTrim: true,
248
- numberToString: true,
249
- boolToString: true,
250
- });
251
- if (value !== '') item.dataset[key] = value;
252
- }
222
+ if (
223
+ ((key = valueToIDString(key)) !== null)
224
+ && ((value = readAsAttrValue(value)) !== null)
225
+ ) {
226
+ item.dataset[key] = value;
227
+ };
253
228
  };
254
229
  };
255
230
  // set an event handlers for the element
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/html-helper",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "A base HTML-helper library for js",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -46,11 +46,11 @@
46
46
  "#lib/*": "./lib/*"
47
47
  },
48
48
  "dependencies": {
49
- "@ygracs/bsfoc-lib-js": "^0.1.3"
49
+ "@ygracs/bsfoc-lib-js": "^0.1.4"
50
50
  },
51
51
  "devDependencies": {
52
- "jest": "^29.5.0",
53
- "jest-environment-jsdom": "^29.5.0",
52
+ "jest": "^29.6.2",
53
+ "jest-environment-jsdom": "^29.6.2",
54
54
  "minimist": "^1.2.8"
55
55
  }
56
56
  }