javascript | Unsorted

Telegram-канал javascript - JavaScript

31615

A resourceful newsletter featuring the latest and most important news, articles, books and updates in the world of #javascript 🚀 Don't miss our Quizzes! Let's chat: @nairihar

Subscribe to a channel

JavaScript

🌟 Behind the Scenes of bun install" is an epic post by Lydia Hallie of the Bun project covering not only what Bun has done to make its package installation mechanism fast, but also the process and pain points of package installation more generally.

bun

Читать полностью…

JavaScript

👀 Feedsmith 2.0: Web Feed Parsing and Generation Library

As well as parsing feeds of various types, you can also create RSS, Atom, JSON Feed, and OPML files with many common namespaces (iTunes, Podcast, Media RSS, Dublin Core, etc.) – here’s a quick start tutorial for using it both in browsers or Node. GitHub repo.

Maciej Lamberski

Читать полностью…

JavaScript

🤟 Node.js v24.8.0 (Current) Released

The big new feature is added support for inspecting HTTP/2 network calls made from Node in Chrome DevTools. There have also been some cryptography related enhancements and npm gets upgraded to v11.6.

Michaël Zasso

Читать полностью…

JavaScript

🔥 The largest supply-chain attack ever…

Читать полностью…

JavaScript

🎹 Happy Programmers Day!

Читать полностью…

JavaScript

😆

Читать полностью…

JavaScript

CHALLENGE

const createLogger = (prefix) => (message) => `${prefix}: ${message}`;
const createCounter = () => {
let count = 0;
return () => ++count;
};

const withLogging = (fn) => (...args) => {
const result = fn(...args);
console.log(`Called with: ${args}, Result: ${result}`);
return result;
};

const counter = createCounter();
const loggedCounter = withLogging(counter);
const logger = createLogger('INFO');

console.log(loggedCounter());
console.log(logger(loggedCounter()));

Читать полностью…

JavaScript

CHALLENGE

const original = {
name: 'Sarah',
scores: [85, 92, 78],
details: {
age: 25,
city: 'Portland'
}
};

const copy1 = { ...original };
const copy2 = JSON.parse(JSON.stringify(original));

copy1.name = 'Emma';
copy1.scores.push(95);
copy1.details.age = 30;

console.log(original.name, original.scores.length, original.details.age);

Читать полностью…

JavaScript

CHALLENGE

class CustomError extends Error {
constructor(message) {
super(message);
this.name = 'CustomError';
}
}

try {
try {
throw new CustomError('inner error');
} catch (e) {
console.log(e.name);
throw new Error('outer error');
}
} catch (e) {
console.log(e.message);
console.log(e instanceof CustomError);
}

Читать полностью…

JavaScript

CHALLENGE

console.log('1');

setTimeout(() => console.log('2'), 0);

Promise.resolve().then(() => console.log('3'));

queueMicrotask(() => console.log('4'));

setTimeout(() => console.log('5'), 0);

Promise.resolve().then(() => {
console.log('6');
return Promise.resolve();
}).then(() => console.log('7'));

console.log('8');

Читать полностью…

JavaScript

CHALLENGE

const data = { a: 1, b: 2, c: 3 };
const { a, ...rest } = data;
const newObj = { ...rest, a, d: 4 };

const arr = [1, 2, 3, 4, 5];
const [first, , third, ...remaining] = arr;
const result = [...remaining, third, first];

console.log(newObj);
console.log(result);

Читать полностью…

JavaScript

CHALLENGE

class EventManager {
constructor() {
this.listeners = new Map();
}

addListener(event, callback) {
if (!this.listeners.has(event)) {
this.listeners.set(event, new Set());
}
this.listeners.get(event).add(callback);
}

removeListener(event, callback) {
this.listeners.get(event)?.delete(callback);
}
}

const manager = new EventManager();
const handler = () => console.log('handled');
manager.addListener('click', handler);
manager.removeListener('click', () => console.log('handled'));
console.log(manager.listeners.get('click').size);

Читать полностью…

JavaScript

✌️ The Many, Many, Many JavaScript Runtimes of the Last Decade

A meaty article (which took a year to put together) covering the myriad of JavaScript runtimes and engines both past and present, from obvious picks like Node.js to cloud platforms and lesser known ‘honorable mentions’. This is a great summary to round out your JS ecosystem knowledge.

Whatever, Jamie

Читать полностью…

JavaScript

CHALLENGE

async function processValues() {
try {
console.log('Start');
const a = await Promise.resolve('First');
console.log(a);
const b = await Promise.reject('Error');
console.log(b);
return 'Done';
} catch (err) {
console.log(err);
return 'Recovered';
} finally {
console.log('Finally');
}
}

processValues().then(result => console.log(result));

Читать полностью…

JavaScript

CHALLENGE

class LightMachine {
constructor() {
this.states = {
green: { next: 'yellow' },
yellow: { next: 'red' },
red: { next: 'green' }
};
this.currentState = 'green';
}

transition() {
this.currentState = this.states[this.currentState].next;
return this.currentState;
}
}

const lightMachine = new LightMachine();
let result = '';
for (let i = 0; i < 5; i++) {
result += lightMachine.transition() + ' ';
}
console.log(result.trim());

Читать полностью…

JavaScript

CHALLENGE

const multiply = (a) => (b) => (c) => a * b * c;

const step1 = multiply(2);
const step2 = step1(3);
const result1 = step2(4);

const result2 = multiply(2)(3)(4);

const partialMultiply = multiply(5);
const result3 = partialMultiply(2)(3);

const doubler = multiply(2)(1);
const result4 = doubler(7);

console.log(result1, result2, result3, result4);

Читать полностью…

JavaScript

CHALLENGE

class EventManager {
constructor() {
this.listeners = new Map();
}

addListener(event, callback) {
if (!this.listeners.has(event)) {
this.listeners.set(event, new Set());
}
this.listeners.get(event).add(callback);
}
}

const manager = new EventManager();
const obj = { name: 'Component' };
manager.addListener('click', () => console.log(obj.name));
obj = null;
console.log(manager.listeners.get('click').size);

Читать полностью…

JavaScript

CHALLENGE

console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
setTimeout(() => console.log('4'), 0);
console.log('5');
Promise.resolve().then(() => {
console.log('6');
return Promise.resolve();
}).then(() => console.log('7'));
queueMicrotask(() => console.log('8'));
console.log('9');

Читать полностью…

JavaScript

CHALLENGE

const obj = {
name: 'Sarah',
regularMethod: function() {
return () => {
console.log(this.name);
};
},
arrowMethod: () => {
return () => {
console.log(this.name);
};
}
};

const regular = obj.regularMethod();
const arrow = obj.arrowMethod();
regular();
arrow();

Читать полностью…

JavaScript

CHALLENGE

const original = {
name: 'Emma',
skills: ['JavaScript', 'Python'],
config: { theme: 'dark', notifications: true }
};

const copy1 = { ...original };
const copy2 = JSON.parse(JSON.stringify(original));
const copy3 = Object.assign({}, original);

copy1.name = 'Sarah';
copy1.skills.push('React');
copy1.config.theme = 'light';

console.log(original.name);
console.log(original.skills.length);
console.log(original.config.theme);

Читать полностью…

JavaScript

CHALLENGE

function createCounter() {
let count = 0;
return {
increment: () => ++count,
decrement: () => --count,
getValue: () => count
};
}

const counter1 = createCounter();
const counter2 = createCounter();
counter1.increment();
counter1.increment();
counter2.increment();
console.log(counter1.getValue() + counter2.getValue());

Читать полностью…

JavaScript

😭 A Major Supply Chain Attack Hits the npm Ecosystem

In July, Socket warned us about a phishing campaign targeting npm package publishers. Sadly, a prolific package author (among others, like DuckDB, who explain how the attack worked on them) fell victim to the scam, resulting in some popular packages becoming compromised (like Chalk, debug, and others).

Gooding, Brown, et al. (Socket)

Читать полностью…

JavaScript

🎨 Eyecons is a VS Code icon theme that automatically adapts the color of icons to fit your editor's main theme – well, from this list anyway.

Читать полностью…

JavaScript

👀 Peaks.js 4.0: UI Component for Interacting with Audio Waveforms

A project originally spawned from the BBC’s R&D department, Peaks renders audio waveforms to a canvas element and allows scrolling, zooming, and the sort of things you might otherwise see in an audio editor. LGPL licensed.

Chris Needham et al.

Читать полностью…

JavaScript

😱 Google Chrome Turns 17: A History

A fantastic walkthrough of Chrome’s origins and its evolution over the years. Addy looks at key milestones (multi-process architecture for example), security, its steps into the world of AI, and more.

Addy Osmani

Читать полностью…

JavaScript

🙂 Mediabunny: A Complete Media Toolkit for JavaScript

Supporting both browsers and Node.js, this library lets you read, write and convert popular media file formats (e.g. MP4, MP3, and more) without needing to lean on dependencies like FFmpeg. You can make thumbnails, extract metadata, write code that gets converted into a video, and more. GitHub repo.

Vanilagy

Читать полностью…

JavaScript

CHALLENGE

class ChatServer {
constructor() {
this.clients = new Set();
this.messageLog = [];
}

connect(client) {
this.clients.add(client);
return () => this.clients.delete(client);
}

broadcast(message, sender) {
this.messageLog.push(message);
this.clients.forEach(client => {
if (client !== sender) {
client.receive(message);
}
});
}
}

const server = new ChatServer();
const david = { name: 'David', receive: msg => console.log(`David got: ${msg}`) };
const sarah = { name: 'Sarah', receive: msg => console.log(`Sarah got: ${msg}`) };
const emma = { name: 'Emma', receive: msg => console.log(`Emma got: ${msg}`) };

const disconnectDavid = server.connect(david);
server.connect(sarah);
server.connect(emma);
server.broadcast('Hello everyone!', david);
disconnectDavid();
server.broadcast('Is David still here?', sarah);

console.log(server.clients.size);

Читать полностью…

JavaScript

CHALLENGE

function greet(name) {
return `Hello, ${name}!`;
}

function highlight(strings, ...values) {
return strings.reduce((result, str, i) => {
return result + str + (values[i] ? `<em>${values[i]}</em>` : '');
}, '');
}

const user = 'Sarah';
const status = 'online';

console.log(highlight`User ${user} is currently ${status}.`);

Читать полностью…

JavaScript

😂

Читать полностью…

JavaScript

👀 npq: Safely Install Packages by Auditing Them Pre-Install

npq performs several extra steps compared to npm. It consults Snyk’s database of vulnerabilities, looks at the package’s age, download count, and docs, and tries to paint a better picture of what you’re really installing.

Liran Tal

Читать полностью…
Subscribe to a channel