Additional niceties from Ruby corelib/stdlib and even ActiveSupport-isms? #71
Replies: 10 comments 8 replies
-
|
Just thinking out loud here... .assuming one or more of these results in a non-trivial expansion, it might make sense to create npm modules (perhaps under the |
Beta Was this translation helpful? Give feedback.
-
|
Definitely like the |
Beta Was this translation helpful? Give feedback.
-
|
An example of automatic imports, try going to https://whimsy.apache.org/ruby2js/node/esm and entering the following system "echo hi"The resulting javascript will be: |
Beta Was this translation helpful? Give feedback.
-
|
Very cool! |
Beta Was this translation helpful? Give feedback.
-
|
As luck would have it, npm already has a SecureRandom.alphanumeric implementation in base62-random. I've committed experimental support for this (without docs) in 6e11f31 Disjointed thoughts:
|
Beta Was this translation helpful? Give feedback.
-
|
I like all of those ideas, and I would love to have a more official subsystem for imports, not only on the tracking output side as you mentioned, but I could also envision setting up some autoimports. Not necessarily something full-blown ala Zeitwerk, but maybe a situation where the converter is passed a hash of classes/methods -> paths and then when it encounters that class or method used in a file it makes sure that gets imported from elsewhere in the source tree. For example I write a lot of files where I always have to import three things from one particular file, and if that was just assumed dynamically it would clean things up very nicely. It's the kind of stuff that gives an even more Ruby-esque feel. |
Beta Was this translation helpful? Give feedback.
-
Something like dacda5b perhaps? |
Beta Was this translation helpful? Give feedback.
-
|
Just added a new |
Beta Was this translation helpful? Give feedback.
-
|
JS working example: https://codepen.io/jaredcwhite/pen/MWjvYgb |
Beta Was this translation helpful? Give feedback.
-
|
I've been doing some work on a DateRange TS/JS class on a private project, which got me thinking about implementing Ruby's Range protocol as a Range class with concrete subclasses for DateRange, NumberRange, StringRange etc. That could be used from JS but also have a Ruby2JS interface with a filter that could provide those features in a more Rubyish way. Would that fit here? I've already started working on Date interface that would mirror Ruby. I'm also thinking infinite ranges could be supported using generators where available. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm thinking of starting a list of some obvious niceties we could look at implementing from Ruby's corelib/stdlib, and maybe even popular libraries like ActiveSupport (.present? would be awesome, for example…I always hate how verbose simple string checking has to be in JS). I also think it's likely some will make sense as function filters directly and others might be better suited to implementing via additional NPM packages and imported in.
Maybe using the wiki here for a page to start with would make sense…
or keep a running list in this issue.…https://github.com/rubys/ruby2js/wiki/Ruby-methods-possibly-supported-in-the-future
Beta Was this translation helpful? Give feedback.
All reactions