UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

93 lines (82 loc) 2.21 kB
'use strict' const path = require('path') function isTrue (str) { str = String(str).toLowerCase() return str === 'true' || str === '1' } function isFalse (str) { str = String(str).toLowerCase() return str === 'false' || str === '0' } function isError (value) { return Boolean(value?.message || value instanceof Error) } // Matches a glob pattern to a given subject string function globMatch (pattern, subject) { if (typeof pattern === 'string') pattern = pattern.toLowerCase() if (typeof subject === 'string') subject = subject.toLowerCase() if (typeof subject === 'number' && Number.isInteger(subject)) subject = String(subject) let px = 0 // [p]attern inde[x] let sx = 0 // [s]ubject inde[x] let nextPx = 0 let nextSx = 0 while (px < pattern.length || sx < subject.length) { if (px < pattern.length) { const c = pattern[px] switch (c) { case '?': if (sx < subject.length) { px++ sx++ continue } break case '*': nextPx = px nextSx = sx + 1 px++ continue default: // ordinary character if (sx < subject.length && subject[sx] === c) { px++ sx++ continue } break } } if (nextSx > 0 && nextSx <= subject.length) { px = nextPx sx = nextSx continue } return false } return true } // TODO: this adds stack traces relative to packages/ // shouldn't paths be relative to the root of dd-trace? function calculateDDBasePath (dirname) { const dirSteps = dirname.split(path.sep) const packagesIndex = dirSteps.lastIndexOf('packages') return dirSteps.slice(0, packagesIndex + 1).join(path.sep) + path.sep } function hasOwn (object, prop) { return Object.prototype.hasOwnProperty.call(object, prop) } function normalizeProfilingEnabledValue (configValue) { return isTrue(configValue) ? 'true' : isFalse(configValue) ? 'false' : configValue === 'auto' ? 'auto' : undefined } module.exports = { isTrue, isFalse, isError, globMatch, calculateDDBasePath, hasOwn, normalizeProfilingEnabledValue }