njh / node-owfs

A node.js client library for the owserver protocol in owfs
https://www.npmjs.com/package/owfs
MIT License
10 stars 4 forks source link

Convert string responses to native int/float #21

Open njh opened 7 years ago

njh commented 7 years ago

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;
    }