Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert string responses to native int/float #21

Open
njh opened this issue Dec 22, 2016 · 0 comments
Open

Convert string responses to native int/float #21

njh opened this issue Dec 22, 2016 · 0 comments

Comments

@njh
Copy link
Owner

njh commented Dec 22, 2016

This is what I was doing in node-red-contrib-owfs:

    function parseResult(result) {
        if (typeof result.match === 'function') {
            if (result.match(/^\-?\d+\.\d+$/)) {
                return parseFloat(result);
            } else if (result.match(/^\-?\d+$/)) {
                return parseInt(result);
            }
        }
        return result;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant