UNPKG

@microsoft/applicationinsights-core-js

Version:

Microsoft Application Insights Core Javascript SDK

56 lines (54 loc) 2.56 kB
/* * Application Insights JavaScript SDK - Core, 3.3.6 * Copyright (c) Microsoft and contributors. All rights reserved. */ "use strict"; import { strShimUndefined } from "@microsoft/applicationinsights-shims"; import { strSubstr, strSubstring } from "@nevware21/ts-utils"; import { _DYN_LENGTH } from "../__DynamicConstants"; import { STR_EMPTY } from "./InternalConstants"; import { random32 } from "./RandomHelper"; // Added to help with minfication export var Undefined = strShimUndefined; export function newGuid() { var uuid = generateW3CId(); return strSubstring(uuid, 0, 8) + "-" + strSubstring(uuid, 8, 12) + "-" + strSubstring(uuid, 12, 16) + "-" + strSubstring(uuid, 16, 20) + "-" + strSubstring(uuid, 20); } /** * The strEndsWith() method determines whether a string ends with the characters of a specified string, returning true or false as appropriate. * @param value - The value to check whether it ends with the search value. * @param search - The characters to be searched for at the end of the value. * @returns true if the given search value is found at the end of the string, otherwise false. */ export function strEndsWith(value, search) { if (value && search) { var len = value[_DYN_LENGTH /* @min:%2elength */]; var start = len - search[_DYN_LENGTH /* @min:%2elength */]; return strSubstring(value, start >= 0 ? start : 0, len) === search; } return false; } /** * generate W3C trace id */ export function generateW3CId() { var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]; // rfc4122 version 4 UUID without dashes and with lowercase letters var oct = STR_EMPTY, tmp; for (var a = 0; a < 4; a++) { tmp = random32(); oct += hexValues[tmp & 0xF] + hexValues[tmp >> 4 & 0xF] + hexValues[tmp >> 8 & 0xF] + hexValues[tmp >> 12 & 0xF] + hexValues[tmp >> 16 & 0xF] + hexValues[tmp >> 20 & 0xF] + hexValues[tmp >> 24 & 0xF] + hexValues[tmp >> 28 & 0xF]; } // "Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively" var clockSequenceHi = hexValues[8 + (random32() & 0x03) | 0]; return strSubstr(oct, 0, 8) + strSubstr(oct, 9, 4) + "4" + strSubstr(oct, 13, 3) + clockSequenceHi + strSubstr(oct, 16, 3) + strSubstr(oct, 19, 12); } //# sourceMappingURL=CoreUtils.js.map