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

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

Open
WolfWalter opened this issue Jun 29, 2023 · 5 comments
Open

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

WolfWalter opened this issue Jun 29, 2023 · 5 comments
Labels
feature-request New feature or request

Comments

@WolfWalter
Copy link

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
Copy link

dsiebes commented Jul 19, 2023

+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
Copy link
Author

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;

@onlybakam onlybakam added the feature-request New feature or request label Dec 11, 2023
@KeynesYouDigIt
Copy link

KeynesYouDigIt commented Sep 16, 2024

Number.isNaN(Number("asdf"))

Appears to work as well. Any reason we couldnt add this to util? as a safeParser or something? I know this is the community so I think I'm just screaming into the void here 🙃

Edit - this does NOT work as expected when deployed. Amazing.

AppSync Error: Invalid function: Number [code: INVALID_FUNCTION_INVOCATION] 

@KeynesYouDigIt
Copy link

Note the above does not work, amazing.

AppSync Error: Invalid function: Number [code: INVALID_FUNCTION_INVOCATION] 

@KeynesYouDigIt
Copy link

const value = +someString doesnt allow for whitespace, so maybe +someString.trim() is a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants