aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
506 stars 32 forks source link

APPSYNC_JS support for parseInt, parseFloat and Number() #303

Open WolfWalter opened 1 year ago

WolfWalter commented 1 year ago

I tried to convert my object keys from string to numbers, but got "The code contains one or more errors. " as a response when I tried to use parseInt, parseFloat or Number().

dsiebes commented 1 year ago

+1

myReturnObject = {}
stringFromPreviousResult = "52.525243"
myReturnObject.property = Number(stringFromPreviousResult)

What is the proper way to convert a string to a number with APPSYNC_JS runtime?

WolfWalter commented 1 year ago

As a workaround I used the unary operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus

const test = '123';
const testNumber = +test;