Fork me on GitHub
#clojurescript
<
2020-01-04
>
valtteri15:01:00

If I have a js-object like (def x #js{"100" "a"}) is there a smart way to access the property "100"? Normal property access with (.-100 x) or (. x -100) doesn’t seem to work. Do I have to use goog.object/get ?

thheller17:01:08

@valtteri yes, goog.object/get is for arbitrary js objects

thheller17:01:50

.-100 doesn't work since x.100 wouldn't be valid javascript either.

valtteri18:01:58

Just wanted to make sure I wasn’t missing something obvious

ec20:01:12

How can I make this in cljs? Get matching group 1 with pattern ^.*(?:\/|v\/|e\/|u\/\w+\/|embed\/|v=)([^#\&\?]*).* (re-seq #"^.*(?:\/|v\/|e\/|u\/\w+\/|embed\/|v=)([^#\&\?]*).*" "") gives invalid token error

ec21:01:40

I just want to extract youtube video id. Probably will need this cljs regex knowledge later too, so best to learn whats wrong with it

p-himik21:01:56

It works for me.

p-himik21:01:11

Also, there's no such thing as "CLJS RegEx". It's JS RegEx.

p-himik21:01:50

But even if you get it working, I would definitely follow Nate Sutton's advice and do this with a URL parser.

ec22:01:19

thx for suggestions but is this a bug with shadow-cljs? This runs fine on js "".split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/) This gives invalid left hand side assign err (clojure.string/split "" #"(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)") ?

enforser22:01:13

What happens if you just try JS interop directly? That is one part of what clojure.string/split should be calling

(.split "" #"(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)")

enforser22:01:39

Looks like the above works on https://clojurescript.io/ I'd make sure that your testing clojure.string/split and the native JS split with the same javascript versions.

ec23:01:11

Interesting, Im using lein reframe template which uses shadow-cljs: 2.8.83 and cljs: 1.10.597 both are seems to latest releases.

mfikes23:01:58

(import '(goog Uri))
(.getPath (Uri. ""))

mfikes23:01:46

^ use goog Uri—it’s built in

deleted23:01:06

cljs.user=> (re-seq #"^.*(?:\w+/|embed/|v=)([^#&?]*).*" "v=hmOZU7Zk10")
(["v=hmOZU7Zk10" "hmOZU7Zk10"])