Skip to content

Instantly share code, notes, and snippets.

View havenchyk's full-sized avatar
🌏
Working from home

Uladzimir Havenchyk havenchyk

🌏
Working from home
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active November 17, 2024 12:06
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
import * as React from 'react';
import { useState } from 'react';
import { useHistory } from 'react-router-dom';
import useAsyncCallback from './useAsyncCallback';
export default function LoginPage() {
let history = useHistory();
return (
<article>
{/* какой-то контент, всё что угодно на странице логина */}
@havenchyk
havenchyk / formatter.js
Last active May 22, 2020 10:08
Format date into US format with `-` instead of `/`: mm-dd-yyyy
const now = new Date();
const options = {
timeZone: 'UTC',
day: '2-digit',
month: '2-digit',
year: 'numeric'
};
const formatter = new Intl.DateTimeFormat("en-US", options);
// mm-dd-yyyy with no library
@just-boris
just-boris / README.md
Last active May 13, 2022 11:16
Use lint-staged to check file sizes

File size checker

Prevents you from accidentially commenting very big assets. Make sure that you have optimized all your assets.

Installation

  1. Add the script to your repo
  2. Configure lint-staged
@ekreutz
ekreutz / ansible_variable_precedence.md
Last active October 13, 2024 21:54
Ansible variable precedence (order, hierarchy)
@ceejbot
ceejbot / esm_in_node_proposal.md
Last active June 20, 2024 10:45
npm's proposal for supporting ES modules in node

ESM modules in node: npm edition

The proposal you’re about to read is not just a proposal. We have a working implementation of almost everything we discussed here. We encourage you to checkout and build our branch: our fork, with the relevant branch selected. Building and using the implementation will give you a better understanding of what using it as a developer is like.

Our implementation ended up differing from the proposal on some minor points. As our last action item before making a PR, we’re writing documentation on what we did. While I loathe pointing to tests in lieu of documentation, they will be helpful until we complete writing docs: the unit tests.

This repo also contains a bundled version of npm that has a new command, asset. You can read the documentation for and goals of that comma

@dmvaldman
dmvaldman / promisesEM.md
Last active June 1, 2024 00:20
Promises as EventEmitters

Promises as EventEmitters

I was trying to understand JavaScript Promises by using various libraries (bluebird, when, Q) and other async approaches.

I read the spec, some blog posts, and looked through some code. I learned how to

@xgrommx
xgrommx / ranges.js
Last active June 13, 2020 23:04
Generate ranges in javascript
const range1 = len => Object.keys(new Int8Array(len)).map(parseFloat);
const range2 = len => Array.apply(null, {length: len}).map(Number.call, Number);
const range3 = (start, end) => Array.apply(null, Array(end - start)).map((_, i) => start + i);
const range4 = (start, end) => [...Array(end - start)].map((_, i) => start + i);
const range5 = len => Object.keys(Array.apply(null, Array(len)));
@DenisIzmaylov
DenisIzmaylov / INDEX.md
Last active February 23, 2017 13:48
JavaScript Best Practicies
@RReverser
RReverser / better-console-log.js
Last active May 9, 2019 21:07
Better console.log in Node
// UPD:
// Now available as npm module!
// Check out https://github.com/RReverser/better-log for details.
console.log = (function (log, inspect) {
return function () {
return log.apply(this, Array.prototype.map.call(arguments, function (arg) {
return inspect(arg, { depth: 1, colors: true });
}));
};