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

JS: Add parse_int(), to_upper_case(), to_lower_case() #17

Merged
merged 9 commits into from
Mar 17, 2024

Conversation

Spooks4576
Copy link
Contributor

@Spooks4576 Spooks4576 commented Mar 7, 2024

What's new

Added a Global StringUtils Library that gets handled globally also added a ParseInt global function similar to what regular js has


For the reviewer

  • I've uploaded the firmware with this patch to a device and verified its functionality
  • I've confirmed the bug to be fixed / feature to be stable

@Willy-JL
Copy link
Member

as per mjs docs:

  • substring("abc", 1, 3) -> "abc".slice(1, 3)
  • slice("abc", 1, 3) -> "abc".slice(1, 3)
  • indexOf("abc", "bc") -> "abc".indexOf("bc")
  • GetLength("abc") -> "abc".length

as for parse_int("123"), mostly ok, just some tiny changes to error handling, nothing major, well done

toUpperCase("abc") and toLowerCase("ABC") i'd like to have on the string objects themselves. i will see if this can be done easily, if not can keep global (though i will move into js_thread.c, having a separate header which actually contains code, and is labelled as a module when its global, is not ideal.

also, please stick to a naming convention. parseint, parse_int, indexOf and GetLength can't possibly all belong to the same API... considering the existing examples from OFW js runner, i'd say the safe bet is snake_case globals, and camelCase module functions.

@Willy-JL
Copy link
Member

adding to string object as "abc".toUpperCase() would go into getprop_builtin_string() of lib/mjs/mjs_exec.c, which means it would end up in firmware flash. i'd rather have it in js_app, so its in fap instead. ill make it respect the global function naming scheme as to_upper_case("abc")

@Willy-JL Willy-JL merged commit d63a07f into Next-Flip:dev Mar 17, 2024
2 checks passed
@Willy-JL Willy-JL changed the title JS : String Utils Global Object + ParseInt Global Function JS: Add parse_int(), to_upper_case(), to_lower_case() Mar 17, 2024
@Willy-JL Willy-JL added the feature New feature or request label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants