r/javascript • u/lavrton • Feb 20 '16
r/javascript • u/[deleted] • Jan 20 '20
SOLID: Interface Segregation Principle in JavaScript and TypeScript
r/javascript • u/xxczaki • Aug 27 '20
light-date - Blazing fast & lightweight (157 bytes) date formatting for Node.js and the browser.
r/javascript • u/CarbonCosma • Feb 16 '22
AskJS [AskJS] I made a VSCode extension that finds functional and logic bugs in JS code
It understands your code and developer's intent, finds bugs, highlights them and suggests the fixes. Provides the best value during the development: write a function, test the output and if not as expected - run it to determine whats wrong and catch bugs. The extension is available in VSCode Marketplace now.
Please check it out and give me some feedback: https://gettensorbox.com .
Demo video link is in the comments.
r/javascript • u/AndyMagill • Sep 03 '25
Creating a JavaScript Debugging Utility to Guard Noisy Production Consoles
I want everyone to know how clever this code is, so I shared it here.
r/javascript • u/jxd-dev • Mar 30 '26
Cookie Banners for shadcn/ui
We build a cookie banner component as a shadcn registry item so the component lives in your repo rather than loading from a CDN.
One command to install, styled with Tailwind, and driven by a single config file that also powers your Privacy Policy and Cookie Policy docs.
ConsentGate can conditionally render scripts based on what the user consented to.
r/javascript • u/mark_tyler • Mar 27 '24
AskJS [AskJS] Are there any component libraries left that are not for React?
Donβt asky why, I know everyone does React/Vue these days. I know of Shoelace, but they miss some critical UI components (autocomplete with backend data for example). Everything else is either 10 years old or require jQuery. Looking for a kit or a list of components built with modern Vanilla JS.
r/javascript • u/mathmul • Nov 07 '25
AskJS [AskJS] Rate my .env parser
Not sure if this will be removed, due to not having the title be in the question form, but you understand what I mean..
Here it is:
import process from 'node:process';
const cache = new Map<string, unknown>();
function expand(value: string, depth = 0): string {
if (value === '' || depth > 10) return value;
return value.replaceAll(/\${([^}]+)}|\$(\w+)/gi, (_: string, braced?: string, simple?: string) => {
const key = (braced ?? simple)!;
const [ref, fallback] = key.split(':-');
const refValue = process.env[ref];
if (refValue !== undefined) return expand(refValue, depth + 1);
return fallback ?? '';
});
}
function cast<T>(value: string): T {
const lower = value.toLowerCase();
if (lower === 'true') return true as T;
if (lower === 'false') return false as T;
if (lower === 'null') return null as T;
if (value.trim() !== '') {
const number = Number(value);
if (!Number.isNaN(number) && String(number) === value) return number as T;
}
if ((value.startsWith('{') && value.endsWith('}')) || (value.startsWith('[') && value.endsWith(']'))) {
try {
return JSON.parse(value) as T;
} catch {
/* ignore */
}
}
return value as T;
}
/**
* Returns an environment variable, parsed and cached.
*
* Features:
* - Expands nested refs like ${FOO} or $BAR
* - Converts "true"/"false"/"null" and numeric strings
* - Parses JSON arrays/objects
* - Caches resolved values
* - Returns `defaultValue` if environment variable is missing; logs an error if both value and default are empty
*/
export function env<T = string>(key: string, defaultValue?: T): T {
if (cache.has(key)) return cache.get(key) as T;
const raw = process.env[key];
if (raw === undefined || raw.trim() === '') {
if (defaultValue === undefined) {
console.error(`Missing required environment variable: ${key}`);
return defaultValue as T;
}
cache.set(key, defaultValue as T);
return defaultValue as T;
}
const expanded = expand(raw);
const value = cast(expanded);
cache.set(key, value as T);
return value as T;
}PS: I have no idea how Laravel's env() function works under the hood, only that it allows for default values, if the key is missing or has no value in the .env file.
r/javascript • u/orrymr • Oct 28 '25
Fought ESM-only Faker v10 with Jest... My blood, sweat, and transformIgnorePatterns tears.
This ESM vs CommonJS thing hurts my brain sometimes.
r/javascript • u/[deleted] • Apr 10 '14
"colbert bump makes unofficial .js logo, rather official .js logo"
r/javascript • u/nschubach • May 12 '20
AskJS [AskJS] Is it just me or is the Async/Await pattern NOT easier to understand/use in a lot of cases?
I get it, await CAN be easier to understand for some cases, but a lot of the examples I see out there (both in production code and in example blogs) seem to hand-wave some assumptions, while deriding promises for making some of it's own.
One example is right from MDN here where then is a swear word. You are making an assumption that the developer knows that fetch body blob() is an promise/await-able function. If you didn't know that and ran the example as follows:
async function myFetch() {
let response = await fetch('coffee.jpg');
let myBlob = response.blob(); // removed await
....It changes the function of the block of code in serious ways.
However, in the promise example:
fetch('coffee.jpg')
.then(response => response.blob())There's no mental consideration that the blob() method requires an await. The promise.then will inherently await for the result.
Now, I understand that await "feels" more comfortable for those that think in a procedural manner. "I have to do this, this, and this in this order." But it seems to scoff at declarative convention and declare itself the winner of some ephemeral readability/usability debate. I personally have no issue with a then chain. And it lends itself to the same step by step process in my head. It covers the above concern without a second thought from the developer and I think handles the situation in a more elegant fashion.
I understand await is the new hotness, but I think some of the hate that promises get is undeserved.
That's not even considering the third example they just replaced the fetch.then with a function call that does exactly the same thing...
r/javascript • u/talJoffe • Feb 09 '20
βHoistingβ doesnβt really exist in JavaScript! π± according to ECMAScript
r/javascript • u/Wake08 • Nov 03 '22
Be Careful With JavaScript Default Parameters!
r/javascript • u/nufannada • Aug 10 '16
12 extremely useful hacks for JavaScript!
r/javascript • u/therealtimcoulter • Jul 23 '19
I said I'd bring more blockchain content. Read how Truffle is integrating Drizzle into Vue!
r/javascript • u/berensteinbeers007 • Jan 24 '25
AskJS [AskJS] Which OOP style to use in current-gen JS?
For the most part I largely ignored classes when they were made introduced since at that point it is just syntactic sugar on top of the already powerful prototypal inheritance. Eventually I ignored "classes" altogether when the frameworks and libraries I used are mostly functional in structure.
Class
class MyClass {
constructor(x, y) {
this.x = x;
this.y = y;
}
...
}Function constructor
function MyConstructor(x, y){
this.x = x;
this.y = y;
}
MyConstructor.prototype.myMethod = ....Factory
function MyFactory(x, y){
function myMethod(){
...
}
return { myMethod };
}And other approaches like the old OLOO by Kyle SImpson.
What are your opinions on what OOP styles to use? Sell me on them.
r/javascript • u/Consistent_Yak6765 • Feb 13 '25
I created a small functional Netflix clone with a custom video player using React Native
magically.lifer/javascript • u/ergo14 • May 08 '17
Comcast Presentation: Web Components: The Future of Web Development is Here
r/javascript • u/devxpy • Mar 02 '18
help [RANT] Why is JS ES6 import syntax designed with such incompetence?
Usually, in python, I can do
from x import y
Now, this is great becase my editor (PyCharm) can suggest me x, the package name and then y, that package's module, AS I TYPE.
But in JS,
import y from x
Here my editor doesn't tell me anything until I write a full export statement. Then when i try to edit that statement, it makes suggestions.
Why is this designed so badly? using from x import y is so much faster and natural, and still, somehow JS decided to mess up such a basic concept.