UNPKG

parse-domain

Version:

Splits a hostname into subdomains, domain and (effective) top-level domains

39 lines 2.43 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import * as path from "path"; import * as url from "url"; import * as fs from "fs"; import { fetchBuildSerializeTries } from "../update-tries.js"; import { PUBLIC_SUFFIX_URL } from "../config.js"; const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); const writeTriesToFiles = (_a) => __awaiter(void 0, [_a], void 0, function* ({ serializedIcannTrie, serializedPrivateTrie, }) { const indexOfScriptArg = process.argv.lastIndexOf("--"); const targetDirectories = process.argv.slice(indexOfScriptArg + 1); yield Promise.all(targetDirectories.map((targetDirectory) => __awaiter(void 0, void 0, void 0, function* () { const pathToIcannTrie = path.resolve(__dirname, targetDirectory, "icann.js"); const pathToPrivateTrie = path.resolve(__dirname, targetDirectory, "private.js"); const pathToTrieInfoFile = path.resolve(__dirname, targetDirectory, "info.json"); console.warn(`Writing ${pathToIcannTrie}...`); console.warn(`Writing ${pathToPrivateTrie}...`); console.warn(`Writing ${pathToTrieInfoFile}...`); yield Promise.all([ fs.promises.writeFile(pathToIcannTrie, `export default ${JSON.stringify(serializedIcannTrie)};`), fs.promises.writeFile(pathToPrivateTrie, `export default ${JSON.stringify(serializedPrivateTrie)};`), fs.promises.writeFile(pathToTrieInfoFile, JSON.stringify({ updatedAt: new Date(), })), ]); }))); }); export const done = (() => __awaiter(void 0, void 0, void 0, function* () { console.warn(`Fetching public suffix list from ${PUBLIC_SUFFIX_URL}...`); yield writeTriesToFiles(yield fetchBuildSerializeTries()); }))(); //# sourceMappingURL=update-tries.js.map