UNPKG

@sentry/core

Version:
1 lines 1.17 kB
{"version":3,"file":"parseSampleRate.js","sources":["../../../src/utils/parseSampleRate.ts"],"sourcesContent":["/**\n * Parse a sample rate from a given value.\n * This will either return a boolean or number sample rate, if the sample rate is valid (between 0 and 1).\n * If a string is passed, we try to convert it to a number.\n *\n * Any invalid sample rate will return `undefined`.\n */\nexport function parseSampleRate(sampleRate: unknown): number | undefined {\n if (typeof sampleRate === 'boolean') {\n return Number(sampleRate);\n }\n\n const rate = typeof sampleRate === 'string' ? parseFloat(sampleRate) : sampleRate;\n if (typeof rate !== 'number' || isNaN(rate) || rate < 0 || rate > 1) {\n return undefined;\n }\n\n return rate;\n}\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAC,UAAU,EAA+B;AACzE,EAAE,IAAI,OAAO,UAAA,KAAe,SAAS,EAAE;AACvC,IAAI,OAAO,MAAM,CAAC,UAAU,CAAC;AAC7B;;AAEA,EAAE,MAAM,IAAA,GAAO,OAAO,UAAA,KAAe,QAAA,GAAW,UAAU,CAAC,UAAU,CAAA,GAAI,UAAU;AACnF,EAAE,IAAI,OAAO,SAAS,QAAA,IAAY,KAAK,CAAC,IAAI,CAAA,IAAK,OAAO,CAAA,IAAK,IAAA,GAAO,CAAC,EAAE;AACvE,IAAI,OAAO,SAAS;AACpB;;AAEA,EAAE,OAAO,IAAI;AACb;;;;"}