MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / getTypedValue

Function getTypedValue

frontend/common/utils/utils.tsx:635–672  ·  view source on GitHub ↗
(
    str: FlagsmithValue,
    boolToString?: boolean,
    testWithTrim?: boolean,
  )

Source from the content-addressed store, hash-verified

633 },
634
635 getTypedValue(
636 str: FlagsmithValue,
637 boolToString?: boolean,
638 testWithTrim?: boolean,
639 ) {
640 if (typeof str === 'undefined') {
641 return ''
642 }
643 if (typeof str !== 'string') {
644 return str
645 }
646
647 const typedValue = testWithTrim ? str.trim() : str
648 // Check if the value is sensible number, returns false if it has leading 0s
649 const isNum = /^-?(0|[1-9]\d*)$/.test(typedValue)
650
651 if (isNum && parseInt(typedValue) > Number.MAX_SAFE_INTEGER) {
652 return `${str}`
653 }
654
655 if (typedValue === 'true') {
656 if (boolToString) return 'true'
657 return true
658 }
659 if (typedValue === 'false') {
660 if (boolToString) return 'false'
661 return false
662 }
663
664 if (isNum) {
665 if (str.indexOf('.') !== -1) {
666 return parseFloat(typedValue)
667 }
668 return parseInt(typedValue)
669 }
670
671 return str
672 },
673 getUtmsFromUrl(): UtmsType {
674 const params = Utils.fromParam() as Record<string, string>
675 return TRACKED_UTMS.reduce((utms, key) => {

Callers

nothing calls this directly

Calls 1

testMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…