@feezal/feezal-element 3.0.10 → 3.0.11
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/feezal-friendly-name.js +24 -0
- package/package.json +2 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Shared friendly-label normalization (U62 / E135 device-health).
|
|
2
|
+
//
|
|
3
|
+
// Lives in @feezal/feezal-element so BOTH the editor (discovery stamping,
|
|
4
|
+
// www/src/feezal-discovery-stamp.js re-exports this) and element packages
|
|
5
|
+
// (e.g. the device-health inspector building its device list) derive labels
|
|
6
|
+
// the SAME way. Pure, dependency-free.
|
|
7
|
+
//
|
|
8
|
+
// Normalize a discovered device/entity name into a friendly, human label:
|
|
9
|
+
// 1. strip a trailing Homematic channel suffix (`…:14` / `…:0` → drop only a
|
|
10
|
+
// trailing `:<digits>`, never a colon elsewhere),
|
|
11
|
+
// 2. underscores → spaces, collapse whitespace runs,
|
|
12
|
+
// 3. capitalize the first letter of each *all-lowercase* word — words that
|
|
13
|
+
// already carry an uppercase letter are left entirely alone, so acronyms
|
|
14
|
+
// and units survive (`kWh`, `CO2`, `WLED` unchanged; `licht` → `Licht`),
|
|
15
|
+
// 4. idempotent — an already-friendly name (`Wohnzimmer Lampe`) is unchanged.
|
|
16
|
+
export function friendlyName(raw) {
|
|
17
|
+
let s = String(raw ?? '').trim();
|
|
18
|
+
if (!s) return '';
|
|
19
|
+
s = s.replace(/:\d+$/, ''); // 1. trailing HM channel suffix
|
|
20
|
+
s = s.replace(/_/g, ' ').replace(/\s+/g, ' ').trim(); // 2. underscores → spaces
|
|
21
|
+
// 3. capitalize the first letter only of words with no existing uppercase.
|
|
22
|
+
s = s.replace(/\S+/g, w => (/[A-Z]/.test(w) ? w : w.charAt(0).toUpperCase() + w.slice(1)));
|
|
23
|
+
return s;
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"feezal-element.js",
|
|
17
17
|
"feezal-conditions.js",
|
|
18
|
+
"feezal-friendly-name.js",
|
|
18
19
|
"feezal-polymer-element.js",
|
|
19
20
|
"feezal-topic-input.js",
|
|
20
21
|
"LICENSE"
|
|
@@ -35,5 +36,5 @@
|
|
|
35
36
|
"url": "git+https://github.com/feezal/feezal.git",
|
|
36
37
|
"directory": "www/packages/@feezal/feezal-element"
|
|
37
38
|
},
|
|
38
|
-
"version": "3.0.
|
|
39
|
+
"version": "3.0.11"
|
|
39
40
|
}
|