Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TransformEvaluator.ts to include decomposeDiacriticalMarks #89

8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
- Remove Transform
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
31 changes: 30 additions & 1 deletion src/services/TransformEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1718,4 +1747,4 @@ export class TransformEvaluator {
console.log("Exiting uuid. result=" + result);
return result;
}
}
}
22 changes: 22 additions & 0 deletions src/test/unit/decomposeDiacriticalMarks.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

});
10 changes: 9 additions & 1 deletion src/utils/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ export function toCamelCase(input: string): string {

return word;
}).join('');
}
}

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, "");
}