Skip to content

Type coercion should be stable #31

@mylesj

Description

@mylesj

That is to say that if x is identified as numerical then the following check should also hold true - else the value should remain of type string:

String( Number( x ) ) === String( x )

For example I have a scenario as follows which leads to an invalid configuration:

foreign_api.verification_token = 000111111       # leading zeros truncated
foreign_api.client_id = 1010101010.10101010101   # too large for float / data loss

I've gotten around this by prefixing an arbitrary token to the value and using the reviver option to remove it, i.e.

foreign_api.verification_token = --000111111 
properties.parse('file', {
    // ...
    reviver: function(key, value){
        if(typeof value === 'string')
            return value.replace(/^--\s*/, '');
        return this.assert();
    }, 
    // ...
);

This seems clunky though and I think most use-cases of node-properties would benefit from stable type-coercion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions