Skip to content

This package will convert your string values/numbers in your request body to numbers either int,float,double. you dont need specifically to convert/parse to int float each time.

License

Notifications You must be signed in to change notification settings

Shahkarkhan440/string-values-to-numbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

string-values-to-numbers

This package will convert your string values/numbers from your request body to numbers either int, float, double. you dont need specifically to convert/parse to int float each time.

This package uses recursive calling mechanism which can convert Numbers values in string in your nested objects, arrays at upto any level.

It handles most Cases like:

String Numbers => "4.5"/"6" => 4.5/6

Boolean String:  "true"/"false"  => true/false

Null String => "null" => null

Undefined String => "undefined" => "undefined" will be consider as string

USAGE:

const YourName = require("string-values-to-numbers")

console.log( YourName(req.body) ) //will filter your request object and return object back

Here are some screenshots of request body before and OUTPUT.

Request Body Screenshot:

request_body

Output Screenshot:

output_body

REQUEST BODY:

{
   "a" : "true",
   "b": {
       "c": "4",
       "d": 4.5
   },
   "e": [
       {
           "f": "4.1",
           "g": {
               "h": [
                   {
                       "i": "3.43"
                   },
                   {
                       "j": "false"
                   }

               ]
           }

       },
       {
           "k": "4"
       },
       4,
       "Shahkar",
       "Rizwan",
       "5.4",
       null,
       "undefined",
       [],
       {},
       false

   ],
   "l": [],
   "m": { },
   "n": true,
   "o": "null",
   "p": "undefined"
}

OUTPUT BODY:

{
    "a": true,
    "b": {
        "c": 4,
        "d": 4.5
    },
    "e": [
        {
            "f": 4.1,
            "g": {
                "h": [
                    {
                        "i": 3.43
                    },
                    {
                        "j": false
                    }
                ]
            }
        },
        {
            "k": 4
        },
        4,
        "Shahkar",
        "Rizwan",
        5.4,
        null,
        "undefined",
        [],
        {},
        false
    ],
    "l": [],
    "m": {},
    "n": false,
    "o": null,
    "p": "undefined"
}
```

For any suggestions & bugs reporting please comment issues. or reach me at shahkarkhan02@gmail.com

About

This package will convert your string values/numbers in your request body to numbers either int,float,double. you dont need specifically to convert/parse to int float each time.

Resources

License

Stars

Watchers

Forks

Packages

No packages published