Created
June 7, 2021 14:58
-
-
Save simonneutert/d1824b4885c1d4581d0ab416d483e222 to your computer and use it in GitHub Desktop.
format objectGUID
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
// source: https://github.com/ldapjs/node-ldapjs/issues/297#issuecomment-137765214 | |
const formatGUID = function (objectGUID) { | |
var data = Buffer.from(objectGUID, 'binary'); | |
// GUID_FORMAT_D | |
var template = '{3}{2}{1}{0}-{5}{4}-{7}{6}-{8}{9}-{10}{11}{12}{13}{14}{15}'; | |
// check each byte | |
for (var i = 0; i < data.length; i++) { | |
// get the current character from that byte | |
var dataStr = data[i].toString(16); | |
dataStr = data[i] >= 16 ? dataStr : '0' + dataStr; | |
// insert that character into the template | |
template = template.replace(new RegExp('\\{' + i + '\\}', 'g'), dataStr); | |
} | |
return template; | |
}; | |
module.exports = formatGUID; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i just extracted the code that @hildoer had written here ldapjs/node-ldapjs#297 (comment)