Created
June 7, 2021 14:58
-
-
Save simonneutert/d1824b4885c1d4581d0ab416d483e222 to your computer and use it in GitHub Desktop.
Revisions
-
simonneutert created this gist
Jun 7, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ // 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;