This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nricValidator(nricInput) { | |
// validation rules | |
const nricRegex = /(\D)(\d{7})(\D)/; | |
const nricTypeRegex = /S|T|F|G/; | |
const weightArr = [2, 7, 6, 5, 4, 3, 2]; | |
const nricLetterST = ['J', 'Z', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A']; | |
const nricLetterFG = ['X', 'W', 'U', 'T', 'R', 'Q', 'P', 'N', 'M', 'L', 'K']; | |
// set nric to all uppercase to remove case sensitivity | |
const nric = nricInput.toUpperCase(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var string = { | |
// pad string with 0 from the left | |
padLeft: function (nr, n, str) { // pad string with 0 from the left | |
if (typeof nr === 'undefined' || nr === '') { | |
return ''; | |
} | |
return Array(n - String(nr).length + 1).join(str || '0') + nr; | |
}, | |
// camelcase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
htmlEntities = { | |
// encode special characters to html encoded characters | |
encode: function (text) { | |
var encodedString = ''; | |
for (i = 0; i < text.length; i++) { | |
if (text.charCodeAt(i) > 127) { | |
encodedString += '&#' + text.charCodeAt(i) + ';'; | |
} else { | |
encodedString += text.charAt(i); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks through entire datalayer object tree to see if object value exists | |
* sample usage: getObject(object, 'object.key1.key2.key3') | |
* @param {object} datalayer - datalayer object | |
* @param {string} objectKey? - optional | |
* @returns {string} returns value | |
*/ | |
export function getObjectValue(datalayer: object, objectKey?: string): string { | |
const object = objectCheck(datalayer, objectKey); | |
if (typeof object === 'string') { |