Skip to content

Instantly share code, notes, and snippets.

View slavafomin's full-sized avatar
✌️
Let's make this World a better place!

Slava slavafomin

✌️
Let's make this World a better place!
View GitHub Profile
{ "foo": 123456789123456789123 }
@slavafomin
slavafomin / 00-typescript-esm.md
Last active April 1, 2025 09:44
Using TypeScript with native ESM

Using TypeScript Node.js with native ESM

This reference guide shows how to configure a TypeScript Node.js project to work and compile to to native ESM.

Rationale

CommonJS module system was introduced by the Node.js developers due to the lack of the notion of "modules" in the original JavaScript (ECMAScript) language specification at that time. However, nowadays, ECMAScript has a standard module system called ESM — ECMAScript Modules, which is a part of the accepted standard. This way CommonJS could be considered vendor-specific and obsolete/legacy. Hopefully, TypeScript ecosystem now supports the "new" standard.

So the key benefits are:

const provider = new HttpProvider('https://toncenter.com/api/v2/jsonRPC', {
apiKey: '…',
});
const wallet = new WalletV3ContractR2(provider, {
publicKey,
});
(async () => {
@slavafomin
slavafomin / get-nft-item-content.ts
Last active June 14, 2022 17:58
Get TON NFT item content
import TonWeb from 'tonweb';
(async () => {
const tonweb = new TonWeb(
new TonWeb.HttpProvider()
);
@slavafomin
slavafomin / 0-get-address-transactions.ts
Last active February 13, 2025 19:03
TON (TonWeb) — get address transactions in JavaScript (TypeScript)
import TonWeb from 'tonweb';
import {
BatchLoadedHandler,
getAddressTransactions,
HttpErrorHandler,
TransactionDiscoveredHandler,
} from './address-transactions';
import { Transformer } from 'grammy/out/core/client';
import { Cache } from './cache';
export function createCachingTransformer(options?: {
cacheTtl?: number;
}): Transformer {
@slavafomin
slavafomin / grammy-runner-graceful-shutdown.ts
Last active November 21, 2021 09:11
Grammy Runner Graceful Shutdown
const runner = run(bot);
['SIGTERM', 'SIGINT'].forEach(signal =>
process.once(signal, () => runner.isRunning() && runner.stop())
);
@slavafomin
slavafomin / autofocus.directive.ts
Created November 5, 2021 21:53
Angular 11+ autofocus directive
/**
* This smart directive accepts boolean value as an input and focuses the
* element based on the evaluated boolean expression.
*
* Also, the directive could be applied to the input/button/select/a elements
* directly or to any parent element as well. It will search the DOM for the first
* suitable element to focus automatically.
*/
@slavafomin
slavafomin / .gitignore
Created September 22, 2020 12:20
.gitignore template for JavaScript or Node.js projects
# IDEA-based IDEs
/.idea/
# Build files
**/dist/
# Dependencies
**/node_modules/
# Temp files
{
"name": "test",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"accepts": {
"version": "1.3.7",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
"integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==",