diff --git a/CHANGELOG.md b/CHANGELOG.md index 71641f4..727c6cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ This changelog is following the recommended format by [keepachangelog](https://k ## [Unreleased] +## [1.3.3] - 2024-09-19 + +### Added + +- Added transform evaluation support for `decomposeDiacriticalMarks` (cf. [#90](https://github.com/yannick-beot-sp/vscode-sailpoint-identitynow/issues/90)) by [@Semperverus](https://github.com/Semperverus) + ## [1.3.2] - 2024-07-03 ### Added @@ -389,4 +395,4 @@ This changelog is following the recommended format by [keepachangelog](https://k - Open Sources and Transforms - Save Sources and Transforms - Create Transform -- Remove Transform \ No newline at end of file +- Remove Transform diff --git a/README.md b/README.md index 5303678..bc1424e 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,10 @@ The patterns defined above use the following tokens: ## Release Notes +## 1.3.3 + +- Added support for `decomposeDiacriticalMarks` transform evaluation (cf. [#90](https://github.com/yannick-beot-sp/vscode-sailpoint-identitynow/issues/90)) by [@Semperverus](https://github.com/Semperverus) + ## 1.3.2 - Updated schema for lifefycle state (`identityState`) diff --git a/src/services/TransformEvaluator.ts b/src/services/TransformEvaluator.ts index 62ab650..54905e0 100644 --- a/src/services/TransformEvaluator.ts +++ b/src/services/TransformEvaluator.ts @@ -276,6 +276,9 @@ export class TransformEvaluator { case 'dateFormat': result = await this.dateFormat(attributes); break; + case 'decomposeDiacriticalMarks': + result = await this.decomposeDiacriticalMarks(attributes); + break; case 'e164phone': result = await this.e164phone(attributes); break; @@ -901,6 +904,32 @@ export class TransformEvaluator { return result; } + async decomposeDiacriticalMarks(attributes: any) { + console.log("Entering method decomposeDiacriticalMarks"); + let result = undefined; + + let input = this.input; + + if (input === undefined) { + if (attributes.input !== undefined) { + input = attributes.input; + + if (typeof input === 'object') { + input = await this.evaluateChildTransform(input); + } + + if (input === undefined) { + return; + } + } + } + + result = input.normalize('NFKD').replace(/[\u0300-\u036f]/g, ""); + + console.log("Exiting decomposeDiacriticalMarks. result=" + result); + return result; + } + async e164phone(attributes: any) { console.log("Entering method e164phone"); let result = undefined; @@ -1718,4 +1747,4 @@ export class TransformEvaluator { console.log("Exiting uuid. result=" + result); return result; } -} \ No newline at end of file +} diff --git a/src/test/unit/decomposeDiacriticalMarks.test.ts b/src/test/unit/decomposeDiacriticalMarks.test.ts new file mode 100644 index 0000000..9f04cf2 --- /dev/null +++ b/src/test/unit/decomposeDiacriticalMarks.test.ts @@ -0,0 +1,22 @@ +import * as assert from 'assert'; +import { it, describe } from 'mocha'; +import { toCamelCase } from '../../utils/stringUtils'; + +suite('decomposeDiacriticalMarks Test Suite', () => { + // vscode.window.showInformationMessage('Start all tests.'); + describe('decomposeDiacriticalMarks', () => { + const tests = [ + { args: 'Āric', expected: 'Aric' }, + { args: 'Dubçek', expected: 'Dubcek' }, + { args: 'Amélie', expected: 'Amelie' }, + { args: "àáâãäåçèéêëìíîïñòóôõöùúûüýÿ", expected: 'aaaaaaceeeeiiiinooooouuuuyy' }, + ]; + tests.forEach(({ args, expected }) => { + it(`should correctly format ${args}`, () => { + const result = decomposeDiacriticalMarks(args); + assert.strictEqual(result, expected); + }); + }); + }); + +}); diff --git a/src/utils/stringUtils.ts b/src/utils/stringUtils.ts index c323b60..0db8544 100644 --- a/src/utils/stringUtils.ts +++ b/src/utils/stringUtils.ts @@ -48,4 +48,12 @@ export function toCamelCase(input: string): string { return word; }).join(''); -} \ No newline at end of file +} + +export function decomposeDiacriticalMarks(input: string): string { + return input + // Decompose the string into separate unicode symbols for diacritical marks in compatibility mode, + .normalize('NFKD') + // Remove the unicode diacritical marks. + .replace(/[\u0300-\u036f]/g, ""); +}