Client side implementation of the DHIS2 code (uid) generator. (CodeGenerator.java)
This module is used to generate and validate DHIS2 uids. A valid DHIS2 uid is a 11 character string which starts with a letter from the ISO basic Latin alphabet.
Methods
(static) generateUid() → {string}
Generate a valid DHIS2 uid. A valid DHIS2 uid is a 11 character string which starts with a letter from the ISO basic Latin alphabet.
Example
import { generateUid } from 'd2/lib/uid';
generateUid();
Returns:
A 11 character uid that always starts with a letter.
- Type
- string
(static) isValidUid(code) → {boolean}
Tests whether the given code is valid.
Example
import { isValidUid } from 'd2/lib/uid';
isValidUid('JkWynlWMjJR'); // true
isValidUid('0kWynlWMjJR'); // false (Uid can not start with a number)
isValidUid('AkWy$lWMjJR'); // false (Uid can only contain alphanumeric characters.
Parameters:
Name | Type | Description |
---|---|---|
code |
string | The code to validate. |
Returns:
Returns true if the code is valid, false otherwise.
- Type
- boolean