www.sonarsource.com

cross-posted from: https://programming.dev/post/11927506 > Many times when I’ve tried to write some code in Node.js using ES modules I’ve found myself reaching for __dirname and then looking up how to replace it. Now Node.js, Deno and Bun support import.meta.dirname. Check out the article for more detail.

3
0
www.sonarsource.com

Many times when I’ve tried to write some code in Node.js using ES modules I’ve found myself reaching for __dirname and then looking up how to replace it. Now Node.js, Deno and Bun support import.meta.dirname. Check out the article for more detail.

13
0
A comprehensive guide to the dangers of Regular Expressions in JavaScript
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearPH
    philnash
    Now 100%

    JavaScript's regex engine isn't the only one to have these problems. There certainly are other implementations, like Re2 and Rust's implementation, that don't have this issue. But they also lack some of the features of the JS implementation too.

    5
  • A comprehensive guide to the dangers of Regular Expressions in JavaScript
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearPH
    philnash
    Now 100%

    The only real way to validate an email address is send it an email and see if it arrives! I'm sure many of us have fallen to the urge to validate an email with a regex though, and yes, it's just too dangerous! I definitely like the simplicity of checking for an @.

    I think regular expressions are actually very tempting to use because they seem hard. I feel like I go through this XKCD comic every time the opportunity to use a regex comes up. But string functions often have the answer. I hope, if this article achieves anything, it just stops people using regex to trim whitespace!

    3
  • redd.one

    Click bait title, but this post goes into depth about using tsconfig.json correctly and across different layers of your project.

    16
    1
    www.sonarsource.com

    This is a follow up to my previous article on how to get more TypeScript benefits in your JavaScript. This goes into how to add types using JSDoc or TypeScript declaration files.

    13
    0
    Hands on with the Node.js test runner
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearPH
    philnash
    Now 100%

    I think you're absolutely right about the difficulty for developers inadvertently getting the legacy assert behaviour. Though I hope if they do that, they at least recognise that they can use the strict methods.

    The early module had both non-strict and strict methods, even from that early time, so the original author recognised the need for using ===, but I guess wanted to be flexible and allow for == usage too. Perhaps this was a bad decision, but it was made in version 0.1.21, so I would guess there was a lot of fast work going on with Node at the time and maybe not everything was thought through in as much depth as it could be. It's possible that one day the strict module may take over the place of the existing assert module, but that would be quite the breaking change!

    1
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearPH
    Now
    22 7

    philnash

    programming.dev