google / react-schemaorg

Type-checked Schema.org JSON-LD for React
Apache License 2.0
481 stars 19 forks source link

Return undefined for null values? #12

Closed ntucakovic closed 4 years ago

ntucakovic commented 4 years ago

image

What do you think about omitting null values, so those fall in the same bucket as the default switch case? I'd prefer to have a clean output with all valid values, and skipping null entries without having to check in each <JsonLd> invocation?

        switch (typeof value) {
            case "object":
                return value; // JSON.stringify will recursively call replacer.
            case "number":
            case "boolean":
            case "bigint":
                return value; // These values are not risky.
            case "string":
                return value.replace(/[&<>'"]/g, replace);
            default: {
                // We shouldn't expect other types.
                isNever(value);
                // JSON.stringify will remove this element.
                return undefined;
            }
        }
Eyas commented 4 years ago

That sounds like a reasonable change. It would entail returning undefined in the case "object" case (since typeof null === "object").

Are you willing to make this PR?