2023-04-01から1ヶ月間の記事一覧

JavaScript - 正規表現

let w3 = " 99 " console.log(w3.match(/^\s*[0-9]+\s*$/)) // [ ' 99 ', index: 0, input: ' 99 ', groups: undefined ] console.log("[" + w3.replace(/^\s+|\s+$/g, "") + "]") // [99]

JavaScript - Set

let s = new Set() s.add("a") s.add("a") s.add("b") console.log("has b:" + s.has("b")) console.log(s.values()) console.log(s.entries()) // has b:true // [Set Iterator] { 'a', 'b' } // [Set Entries] { [ 'a', 'a' ], [ 'b', 'b' ] }

JavaScript - Map

let map = new Map() map.set("a", 1) map.set("b", 2) console.log("siez:" + map.size) console.log("getValue a:" + map.get("a")) map.forEach((value, key) => { console.log(key + "/" + value) }) // siez:2 // getValue a:1 // a/1 // b/2

JavaScript - Object key,valueを取得

let hash = { keyA: "value-a", keyB: "value-b", } //---------- Object.keys Object.keys(hash).map((key) => console.log(key + "/" + hash[key])) //---------- Object.entries for (const [key, value] of Object.entries(hash)) { console.log(`${key}…

node - csv

const fs = require("fs") const { parse } = require("csv-parse/sync") const stringifySync = require("csv-stringify/sync") // 入力CSV // Header 1,Header 2,Header 3 // Row 1 - Col 1,Row 1 - Col 2,Row 1 - Col 3 // Row 2 - Col 1,Row 2 - Col 2,R…

node - sql server接続

tediousjs.github.io github.com $ node index.js db connected { deptno: 10, dname: 'ACCOUNTING', loc: 'NEW YORK' } { deptno: 20, dname: 'RESEARCH', loc: 'DALLAS' } { deptno: 30, dname: 'SALES', loc: 'CHICAGO' } { deptno: 40, dname: 'OPERATIO…

node - コマンド実行

const { exec, execSync } = require("child_process") // 非同期 exec("ls -al", (err, stdout, stedrr) => { if (err) { console.log(err) } console.log(stdout) }) // 同期 const stdout = execSync("ls -al").toString() console.log(stdout)

node - file処理

const glob = require("glob") const fs = require("fs") // ファイル一覧取得 const files = glob.sync("./work_dir/**", { nodir: true }) //console.log(files) files.forEach((f) => { console.log(`<${f}>`) console.log(fs.readFileSync(f).toString())…

jq - 条件抽出

# 抽出 $ cat sample.json | jq '.items[]' | jq 'select(.owner.type == "Organization")' or $ cat sample.json | jq '[.items[]]' | jq 'map(select(.owner.type == "Organization" or .owner.type == "User"))' or $ cat _sample.json | jq '.items[] | …

JavaScript - sample

const fs = require("fs") const data = JSON.parse(fs.readFileSync("test-data.json")) function isEqual(o, name, targets) { return targets.some((t) => { return t === o[name] }) } function isContainList(o, name, targets) { return targets.some(…

node.js - jsonファイル読み書き

const fs = require("fs") const data = JSON.parse(fs.readFileSync("sample.json")) const results = data.items.find((x) => x.owner.type == "User") fs.writeFileSync("./result.json", JSON.stringify(results, null, 2), "utf8")

tool - jq

stedolan.github.io

javascript - linq

dev.classmethod.jp

javascript - sql server

www.kwbtblog.com