Skip to content

Instantly share code, notes, and snippets.

@jrson83
jrson83 / Glob.js
Created December 30, 2022 00:35 — forked from bgoonz/Glob.js
class Glob {
constructor(glob) {
this.glob = glob;
// We implement glob matching using RegExp internally.
// ? matches any one character except /, and * matches zero or more
// of those characters. We use capturing groups around each.
let regexpText = glob.replace("?", "([^/])").replace("*", "([^/]*)");
// We use the u flag to get Unicode-aware matching.
@jrson83
jrson83 / deno-tools.js
Created January 10, 2023 15:17 — forked from ndesmic/deno-tools.js
node tools
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];
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 (台北標準時間)"
@jrson83
jrson83 / node12.js
Created January 12, 2023 06:19 — forked from gpDA/node12.js
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
@jrson83
jrson83 / keyboard-move.js
Created January 16, 2023 16:21 — forked from kirbee/keyboard-move.js
Small node program reading each keystroke from the command line
const readline = require('readline');
const stdin = process.stdin;
readline.emitKeypressEvents(stdin);
stdin.setRawMode(true);
class Coordinates {
constructor(x = 0, y = 0) {
this.x = x;
@jrson83
jrson83 / cp.js
Created January 20, 2023 17:28 — forked from lmammino/cp.js
Session about Node.js streams with Kelvin
import { createReadStream, createWriteStream } from 'fs'
const source = createReadStream('./assets/moby-dick.txt')
const dest = createWriteStream('./assets/moby-dick-decompressed.txt')
source
.pipe(dest)
@jrson83
jrson83 / package-json.ts
Created January 22, 2023 05:22 — forked from LeeCheneler/package-json.ts
typescript type for package.json
export interface Package {
name: string;
version: string;
description?: string;
keywords?: string[];
homepage?: string;
bugs?: {
url: string;
email: string;
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');
@jrson83
jrson83 / createPackage.ts
Created February 6, 2023 21:43 — forked from mattmazzola/createPackage.ts
Create Package Script
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() {
@jrson83
jrson83 / cypress-plugins-index.js
Created February 6, 2023 21:46 — forked from estefafdez/cypress-plugins-index.js
cypress/plugins/index.js with different configuration files.
// 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)
}