This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const cliArgs = process.argv.slice(2); | |
const key = cliArgs[0]; | |
const val = cliArgs[1]; | |
function parseJSON(string) { | |
const sanitised = string.replace(/\s\$\w*/g, substr => `"__SANITISED__${substr}"`); | |
return JSON.parse(sanitised); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// promisified fs module | |
const fs = require('fs-extra') | |
const path = require('path') | |
function getConfigurationByFile(file) { | |
const pathToConfigFile = path.resolve(__dirname, '../config', `${file}.json`) | |
return fs.readJson(pathToConfigFile) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from 'fs-extra' | |
import * as path from 'path' | |
const packageJsonPath = path.join(__dirname, '..', 'package.json') | |
const buildPath = path.join(__dirname, '..', 'build') | |
const uiPackagePath = path.join(__dirname, '..', 'package') | |
const indexJsPath = path.join(uiPackagePath, 'index.js') | |
const indexDtsPath = path.join(uiPackagePath, 'index.d.ts') | |
async function main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mkdirSync, readFileSync, writeFileSync } from 'fs'; | |
import glob from 'glob'; | |
import path from 'path'; | |
const globAsync = (pattern: string): Promise<string[]> => | |
new Promise<string[]>((res, rej) => | |
glob(pattern, (err, matches) => (err ? rej(err) : res(matches))), | |
); | |
const paths = await globAsync('src/**/*.ts'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Package { | |
name: string; | |
version: string; | |
description?: string; | |
keywords?: string[]; | |
homepage?: string; | |
bugs?: { | |
url: string; | |
email: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createReadStream, createWriteStream } from 'fs' | |
const source = createReadStream('./assets/moby-dick.txt') | |
const dest = createWriteStream('./assets/moby-dick-decompressed.txt') | |
source | |
.pipe(dest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); | |
const stdin = process.stdin; | |
readline.emitKeypressEvents(stdin); | |
stdin.setRawMode(true); | |
class Coordinates { | |
constructor(x = 0, y = 0) { | |
this.x = x; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const string = __filename; | |
// path.sep: / | |
console.log('path.sep:', path.sep); | |
// path.delimiter: : | |
console.log('path.delimiter:', path.delimiter); | |
console.log('------'); | |
// path.dirname(): /Users/gp/Desktop/node_module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var now = new Date(); // Date object | |
now.toDateString() // "Sun Jul 17 2016" | |
now.toLocaleDateString() // "2016/7/17" | |
now.toGMTString() // "Sun, 17 Jul 2016 03:16:49 GMT" | |
now.toISOString() // "2016-07-17T03:16:49.141Z" | |
now.toUTCString() // "Sun, 17 Jul 2016 03:16:49 GMT" | |
now.toLocaleTimeString() // "δΈε11:16:49" | |
now.toLocaleString() // "2016/7/17 δΈε11:16:49" | |
now.toString() // "Sun Jul 17 2016 11:16:49 GMT+0800 (ε°εζ¨ζΊζι)" | |
now.toTimeString() // "11:16:49 GMT+0800 (ε°εζ¨ζΊζι)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function directoryToObject(dir, walkOpts){ | |
const obj = {}; | |
for await(const file of walk(dir, walkOpts)){ | |
const path = relative(dir, file.path); | |
const split = path.split("/"); | |
let currObj = obj; | |
for(let i = 0; i < split.length; i++){ | |
const part = split[i]; |