diff --git a/src/lib/util/checkName.ts b/src/lib/util/checkName.ts index 78a6f75ae..fcb73b9d2 100644 --- a/src/lib/util/checkName.ts +++ b/src/lib/util/checkName.ts @@ -1,3 +1,5 @@ +import { CharacteristicValue, Nullable } from "../../types"; + /** * Checks that supplied field meets Apple HomeKit naming rules * https://developer.apple.com/design/human-interface-guidelines/homekit#Help-people-choose-useful-names @@ -5,15 +7,13 @@ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types -export function checkName(displayName: string, name: string, value: any): void { - const validHK = /^[a-zA-Z0-9\s'-.]+$/; // Ensure only letter, numbers, apostrophe, or dash - const startWith = /^[a-zA-Z0-9]/; // Ensure only letters or numbers are at the beginning of string - const endWith = /[a-zA-Z0-9]$/; // Ensure only letters or numbers are at the end of string +export function checkName(displayName: string, name: string, value: Nullable): void { - if (!validHK.test(value) || !startWith.test(value) || !endWith.test(value)) { + // Ensure the string starts and ends with a Unicode letter or number and allow any combination of letters, numbers, spaces, and apostrophes in the middle. + if (typeof value === "string" && value.length && !(new RegExp(/^[\p{L}\p{N}][\p{L}\p{N} ']*[\p{L}\p{N}]$/u)).test(value)) { console.warn("HAP-NodeJS WARNING: The accessory '" + displayName + "' is getting published with the characteristic '" + name + "'" + " not following HomeKit naming rules ('" + value + "'). " + "Use only alphanumeric, space, and apostrophe characters, start and end with an alphabetic or numeric character, and don't include emojis. " + "This might prevent the accessory from being added to the Home App or leading to the accessory being unresponsive!"); } -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 6804145c6..e6efcbb73 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,20 @@ { "compilerOptions": { - "target": "ES5", - "module": "commonjs", - "downlevelIteration": true, - "importHelpers": true, - "lib": [ - "es2015", - "es2016", - "es2017", - "es2018" - ], + "allowSyntheticDefaultImports": true, "declaration": true, "declarationMap": true, - "sourceMap": true, - "outDir": "./dist", - "rootDir": "./src", - "strict": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, + "importHelpers": true, + "lib": ["ES2022"], + "module": "CommonJS", + "moduleResolution": "node", "preserveConstEnums": true, // do not remove this option! + "outDir": "./dist", + "rootDir": "./src", + "sourceMap": true, + "strict": true, + "target": "ES2022", "useUnknownInCatchVariables": false }, "include": [