All files / src typeOf.ts

100% Statements 15/15
100% Branches 7/7
100% Functions 2/2
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 253x           3x 236x 42x   194x 37x   157x 37x   120x 102x 8x   158x   18x    
import { transform } from "@re-do/utils"
import {
    ExtractableDefinition,
    ExtractableTypeName
} from "./components/internal.js"
 
export const typeOf = (value: any): ExtractableDefinition => {
    if (typeof value === "boolean") {
        return value ? "true" : "false"
    }
    if (typeof value === "string") {
        return `'${value}'`
    }
    if (typeof value === "number") {
        return value
    }
    if (typeof value === "object") {
        if (value === null) {
            return "null"
        }
        return transform(value, ([k, v]) => [k, typeOf(v)])
    }
    return typeof value as ExtractableTypeName
}