« first day (4185 days earlier)      last day (985 days later) » 

06:10
throw back to the good days when the tech fad was NoSQL and ML
now its blockchain and nfts and shit which are 1000x worse
06:27
I kind of prefer the current fad. Mostly because back with NoSQL it was all over the place and you'd cross paths very often. The current one feels like it's further away. Sure there are a bunch of people being loud about it but it's (figuratively) in the next room. Not the (figuratively) in the current one.
So, now I hear muffled conversations about it without needing to understand it. Previously, you almost couldn't help being drowned by details you don't care about.
 
4 hours later…
10:46
Terminal filter is the best
10:58
in Userscript newbies and friends, 5 hours ago, by VLAZ
Just switched back to check. I also don't like the green text next to the syntax highlighted text. The background for OP is too low contrast. The links under the post (share, edit, etc) are inconsistently underlined.
11:42
giving an impression that there are no tests failures, eh?
 
2 hours later…
13:18
Trying to get the friday date. It worked yesterday, but when I log in today, it is now reading as 3/1/2022 and yesterday it was 4/1/2022
const today = new Date();

today.setMinutes(today.getMinutes() - today.getTimezoneOffset())
const first = today.getDate() - today.getDay() + 1;

const monday = new Date(today.setDate(first));
const friday = new Date(today.setDate(first + 4));
Any idea why that would change
13:36
Different months effect the results
13:46
forgot that it's 1st of April today. kek
@BeerusDev Date has a "getDay()" function, that gives you day of week
There is a highly upvote comment/solution on this old post, but when I try it (first.getDate is not a function)
!!> const today = new Date(); today.getDay();
@KarelG 5 Logged: [ ] Took: 0ms
0 = sunday -> 5 = friday
@BeerusDev first aint a Date object anymore
oh
var curr = new Date();

var first = (curr.getDate() + 1) - curr.getDay();

var last = first + 6;
firstday = new Date(curr.setDate(first)).toUTCString();
lastday = new Date(curr.setDate(curr.getDate()+ 4)).toUTCString();
13:58
uhm
14:09
What
did you not want to have monday and friday?
                const today = new Date();

                today.setMinutes(today.getMinutes() - today.getTimezoneOffset())
                const first = (today.getDate() + 1) - today.getDay();
                const last = first + 6;

                const monday = new Date(today.setDate(first)).toLocaleDateString();
                const friday = new Date(today.setDate(today.getDate()+ 4)).toLocaleDateString();
This is what I am using for Monday and friday, it accounts for different months as well
Or would you say there is a better method
this is correct yes, I am just confused by the placement of that + 1
and ofc you have included the timezone now
If I don't include it, first will = sunday
// yours one is telling "let's add a day before we substract it with current DoW"
const first = (today.getDate() + 1) - today.getDay();

// let make it directly monday
const monday = new Date(); // not monday yet
monday.setDate(monday.getDate() - monday.getDay() + 1) // now it is
I just have a different thought process :P
 
2 hours later…
15:56
When you try catch fails for seemingly no reason
try {
  await device.connect();
} catch (e) {
  // Error: The getter 'code' isn't defined for the class 'Object'.
  if (e.code != 'already_connected') {
    rethrow;
  }
} finally {
  _services = await device.discoverServices();
}
TS?
flutter
Ah, OK
it doesn't let you set a type on the parameter
so...
The error didn't make much sense. mind you, it still doesn't but I don't know Flutter.
16:06
wtf isn't it taking the exception param as an exception
Might not be. You can probably throw whatever. throw "ball"
That's terrible thing but valid in some languages.
Which just means the catch clauses have to do stupid checks if you want to be thorough.
in this case e is known to be an object
hence the error
it accepts a second param, which it knows to be a stack trace
so what good is the first param if it's a generic object and i can't access it's properties
(meanwhile all examples show accessing e.code just as i am)
16:34
@VLAZ some languages, ahem, ahem
Yes, there is this one called "JavaScript". Don't know if you've heard of it :P
But also C++
@VLAZ never heard of it other than it's a target for compiling TS and Dart xD
These damned timezones.
I have a user on the west coast, so the issues is when he creates an item the timezone he is in is accounted for on the list item. But when I pull that item to post to a DataTable, I reformat it as so
var transformedDate = new Date(spItem[dateKey]);
When it is read to the initialized to the correct table column, I use a function to reformat it as so
{"data": "Days.0.Date", visible: false, orderable: false,
                    render: function(data, type, row) {
                    if (type === "sort" || type === "type") {
                        return data;
                    }
                        return data.toLocaleDateString();
                    }
                },
16:58
so it is stored as MM/DD/YYYY and that is how the table reads it. When I am using my filter to show only current week items, what it filters by is how it is stored/init in the table so it searches for MM/DD/YYYY
This is how I create the Dates to filter the table
   const today = new Date();

                today.setMinutes(today.getMinutes() - today.getTimezoneOffset())
                const first = (today.getDate() + 1) - today.getDay();
                const last = first + 6;

                const monday = new Date(today.setDate(first)).toLocaleDateString();
                const friday = new Date(today.setDate(today.getDate()+ 4)).toLocaleDateString();
It works fine for east coast users, but west coast users it does not. This is where I get confused
any input would be greatly appreciated
17:45
18 minutes y'all
@VLAZ yeah but NoSQL people were just misguided not mentally insane
@JBis I suppose that is true.
18:02
const iso = "YYYY-MM-DDTHH:mm:ssZZ";
console.log(dayjs("2022-04-01T19:43:13+0200", iso, true).format(iso)); // -> 2022-04-01T19:43:13+0200
console.log(dayjs("2022-01-01T19:04:18+0200", iso, true).format(iso)); // -> Invalid Date
console.log(dayjs("2022-01-01T19:04:18+0200", iso, false).format(iso)); // -> 2022-01-01T18:04:18+0100
bleh... dayjs strict mode does not seem to like offsets
guess I'll replace the Moment.js replacement with Date()
18:22
huh
huh? It's correctly parsing for me. Are you sure this is exactly what the input date is?
s/parsing/formatting
18:42
||> Date("2022-04-01T19:43:13+0200")
@JBis 'Fri Apr 01 2022 14:43:00 GMT-0400 (Eastern Daylight Time)' Logged: [ ] Took: 552ms
why do you need dayjs?
@ShubhamMaheshwari Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
I have an array of strings ['a', 'b', 'c', 'e', 'd'] and need to sort it such that 'a' is always last unless there are 'b' in the string, in which case 'b' should be last and 'a' second to last.

Is there an elegant sort function for this case?
ok
  function getHitSortVal(s) {
    if (s === 'b') return 2;
    if (s === 'a') return 1;
    return 0;
  }

  function sortHitTypes(a, b) {
    const aVal = getHitSortVal(a);
    const bVal = getHitSortVal(b);
    return aVal - bVal;
  }

 l = ['a', 'b', 'c', 'e', 'd']
 result = l.sort(sortHitTypes);
18:54
@duhaime Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
19:09
deciding how to structure data can be difficult
19:27
im on my third iteration now of this particular data set, i think i've got it now
At it's most basic level, i have an object, where each key is a hex value, 0 through 36
representing 12 different amps, 3 channels each
each amp has a name, and an image
an array based on those hex values is inefficient, because of duplication
but having an array of 12 with a sub array for the channels holding the hex values requires a lookup when i receive a new hex value
20:09
Hey JS room
I've got a TS question, assuming I have an interface "IName", implemented by 2 classes "Class1" and "Class2", and I have a map:
"const map = { 'key1': ClassName1, 'key2': ClassName2 }"
How would I define the type of such a map? { [key: string]: ??? }, basically what can "???" be that means: "any class implementing IName"
                const today = new Date();

                today.setMinutes(today.getMinutes() - today.getTimezoneOffset());
                const first = (today.getDate() + 1) - today.getDay();

                const monday = new Date(today.setDate(first)).toLocaleDateString();
                const friday = new Date(today.setDate(today.getDate()+ 4)).toLocaleDateString();

                const fridayNF = new Date(today.setDate(today.getDate()+4));

                $("#jsDateRaw").html(fridayNF);
if I do: const map: {[key: string]: typeof IName}, I get a "'IName' only refers to a type, but is being used as a value here." error
is there a typeof equivalent that would mean: "anything implementing IName"
typeof is a type query, it cannot query what's already a type, hence the error
so is there a similarity to how it's done in Java, iirc: Class<? extends IName> ?
TypeScript's type system has nothing to do with Java's type system
they are completely different - the first is structural, the second is nominal
20:25
@Mehdi It's just IName if you want to restrict to the type or <T extends IName> for a generic
you could do something like that, though:
interface I { a: string }

declare class A implements I { a:string }

declare class B implements I { a: string }

declare class C {    }

type imap<T extends new (...args: any[]) => any> = { [x: string]: InstanceType<T> extends I ? T : never };

const test: imap<typeof A | typeof B | typeof C> = {
    a: A, b: B, c: C
};
and no, typeof (A|B|C) (although it's been proposed)
or what @VLAZ said
@VLAZ wouldn't "IName" mean that the map is expecting "instances" as opposed to a Type?
there is no "Type" in TypeScript for classes. The system is structural. There is a static and instance side of a shape of a given class. When you say class A implements I {}, you define that instances of A all implement I
maybe (most probably) I'm misunderstanding something
thus, there is a helper built-in type InstanceType that allows you to express "here goes a constructor instances of which conform to ..."
which is what you want: "an object with a string-keyed index signature and constructors, instances of which implement IName, as values"
you can even do simpler, again, because TS type system is structural, not nominal:
type imap<T extends new (...args: any[]) => I> = { [x: string]: T };
20:36
maybe to put things into context, what I wanna do is to allow users to provide a "key" to an API. Then based on that key, I fetch the key on a "registry" (the map name->ClassNameType) and create an instance based on the ClassNameType
I could use a Map(key: string -> className: string) and then Object.create based on that className
don't see how any of this is relevant to the problem you described above. And there are 3 solutions to the problem proposed already
But I thought I would actually have a more clean and generic definition since all classes implement an interface IName
and a fourth one...
type imap = { [x: string]: new (...args: any[]) => I };
@OlegValteriswithUkraine yeah, but I'm not sure I can do "imap<typeof A | typeof B | typeof C>" if there are dozens of child classes :)
if you do not care about exact constructors
again, structural system
"any constructor that returns an instance conforming to I" :)
where I is your interface, obviously
as long as their instances conform to your interface, TS couldn't care less about what the constructor is
20:43
Understood, thank you
I need to educate myself more on the subject, JVM-based languages are biasing my appreciation of the TS approach
NP :) just love to stress out that TS !== Java in the slightest, so you might want to throw any comparison that comes to mind out of the window. Those two type systems are completely unrelated
yeah, it seems like it haha
wow, that was a big square lol
check the xkcd attached :)
lol
20:52
for about ten seconds, my neighbors were probably wondering who I am summoning before it occurred to me to turn the volume down
21:02
@Mehdi yeah, just be careful not to apply nominal system ideas to TS's type system - the latter operates on "shapes" rather than concrete types.
yeah, I'm having a bit of a hard time wrapping my head around it
wanna express a constructor? It's new (...args: any[]) => any, meaning "any constructor goes" (the most generic form of one). An instance type? An interface will do. An instance type of a constructor? InstanceType<constructor here> is your friend, etc
aha! so you would reason for the latter by saying: the instance type of an object built by the constructor ..., right?
yeah, something like "an instance type is what the constructor function returns", as simple as that
gotcha, interestingly:
> type T3 = InstanceType<string>;
Type 'string' does not satisfy the constraint 'abstract new (...args: any) => any'.
21:10
string is a primitive
so are: boolean and number
this comes from ECMAScript itself
there are Number, Boolean, and String constructors, though
but they all return, as specced, objects with a given primitive value
new String("a") === "a" // false
properly represented in TypeScript as *Constructor interfaces:
type T1 = InstanceType<NumberConstructor>; // Number
type T2 = InstanceType<StringConstructor>; // String
type T3 = InstanceType<BooleanConstructor>; // Boolean
interface NumberConstructor {
    new(value?: any): Number;
}
^ for example
see, structural? "as long as conforms to the shape of X"
right!
for something to be considered to be a constructor, it must satisfy new (...args: any[]) => any or abstract new (...args: any[]) => any
and that's pretty much it :)
but why is the type of value "any"? given that constructor can only build an object based on a subset of any
any just means "anything goes", nothing more
there isn't anything more than any
21:19
as per spec, you can pass anything to String, Boolean, and Number constructors
they will just coerce the value internally to their corresponding primitive type
thus, value?: any
||> new String(false)
@OlegValteriswithUkraine 'false' Logged: [ ] Took: 0ms
nowadays there is a safer unknown type, but those interfaces were written a long time ago, so the team does not see fit to spend time updating them
@OlegValteriswithUkraine yes, but does it make sense? ex: class T {}; new Number(new T());
||> class T {}; new Number(new T());
@OlegValteriswithUkraine null Logged: [ ] Took: 0ms
21:21
@Mehdi of course it does
@JamesBot wut?
// Number {NaN}
hahah but what does it mean?
haha
class AnswerToLifeUniverseAndEverything extends Number {
    toString() {
        return "42";
    }
}

const str = new String(new AnswerToLifeUniverseAndEverything());
^ each of the constructors, when passed an unexpected value, will call an internal operation coercing the type to a primitive value
so if you override the corresponding exposed userland method (toString() / valueOf()), you will get exactly what you want
It makes sense, just a little bit insane, hardly used
@Mehdi "an instance of Number with a primitive value of Not A Number", duh :) don't ask
hahaha
we re currently in the "don't do it at home, kids" and "everything wrong with JavaScript" territory right now
did you know you can also do this? "wel...".answer = 42;
just don't expect it to not be pointless as the property stops existing when the execution advances to the next line
21:30
yeah we're on that exact territory that made me run away from frontend dev years ago XD
because what do you do when your strings are primitives? You wrap it for a second in an instance of a corresponding constructor!
I'm only back to Typescript thanks to AWS CDK hahah
TypeScript made JS so much better
definitely, I'm really enjoying it, unless I come across some OOP TS specificities that make me read about TS internals XD
well, it's not TS that is to blame for that - it's the Java devs not wanting to learn anything new when jumping ship to JS... Hence we have "classes" with prototype-based inheritance system. Bonkers
21:38
touché (even though I haven't done Java in years haha) :D
TS does its best to cope, but not everything is easy. For example, try to express that the static side of a class conforms to an interface
you mean like this? stackoverflow.com/questions/13955157/… came across this a few hours earlier today
Yup-yup
- static interfaces are not happening (the team expressed explicit distate for the proposal)
- decorators are still experimental
- class expressions with interface-constrained declarations are the clossst thing, but screws type inference
21:55
alright man, thanks for the explanations, I appreciated the exchanges :) have a good one
so, might be a weird question but: I got the following using Jquery $('<a></a>').attr("href", "https://google.com")[0].click();. It works but wondering how to port it to pure javascript. I think I saw somewhere that $() in Jquery could be converted to document.querySelector but it doesn't seem to work when I do that.
@Mehdi NP, likewise :)
|| mdn document createElement
|| mdn HTMLAnchorElement href
22:07
|| mdn HTMLElement click
ah, thanks, I'll into those docs entry :)
22:40
posted on April 01, 2022 by Daniel Gagnon

The Stable channel is being updated to 100.0.4896.64 (Platform version: 14526.57.0) for most Chrome OS devices. This build contains a number of bug fixes and security updates. Systems will be receiving updates over the next several days. If you find new issues, please let us know by vising our forum or filing a bug. Interested in switching channels? Find out how. You

22:55
@NordineLotfi NP :) should be easy to combine

« first day (4185 days earlier)      last day (985 days later) »