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
| class BaseN { | |
| table = undefined | |
| /** @type {bigint} */ | |
| n = undefined | |
| constructor(chars){ | |
| this.table = new Map([...Object.entries(chars).map(([k,v])=>[v,BigInt(k)]),...Object.entries(chars).map(([k,v])=>[BigInt(k),v])]) | |
| this.n = BigInt(chars.length) | |
| } | |
| /** @param {arrayBuffer} buf */ | |
| enc(buf){ |
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
| function isBase64(value){ | |
| if (value == "")return false; | |
| for (let i = 0; i<value.length; ){ | |
| const x = value.slice(i,i+=4); | |
| if (i==value.length-1 && !x.match(/^[a-zA-Z0-9]+={0,4}$/))return false; | |
| if (i<value.length-1 && !x.match(/^[a-zA-Z0-9]+$/))return false; | |
| if (x.length != 4)return false; | |
| } | |
| return true | |
| } |
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
| // license: MIT | |
| /** | |
| * usage: sql`insert into hoge values (2,${`(select json_agg(users) from users)`})` //out: ["insert into hoge values (2,$1)",["(select json_agg(users) from users)"]] | |
| * @template T | |
| * @type {(r:TemplateStringsArray,...v:T[])=>[string, T[]]} | |
| */ | |
| export const sql = (r,...rawValues) => { | |
| const valuearr = [...new Set(rawValues)] | |
| const values = new Map(valuearr.map((v,i) => [v,i+1])) |
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 HElement { | |
| tag: string, attrs: Record<string,string>, children: (HElement|string)[], toHTML(): string, toDOM(): Element | |
| } | |
| export type HComponent = ((attrs:Record<string,string>,children:HElement["children"],componentUtil:HComponentUtil)=>HElement) | |
| export interface HComponentUtil_nonPrivate { | |
| __nativeElement__?:Element | |
| __event__: { | |
| didMount:null|(()=>void) |
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 base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
| const base58Table = {...Object.fromEntries(Object.entries(base58Chars).map(([k,v])=>[v,BigInt(k)])),...base58Chars} | |
| /** @param {arrayBuffer} buf */ | |
| function base58enc(buf){ | |
| const u8 = new Uint8Array(buf) | |
| let int = 0n | |
| u8.forEach( (x,i) => int += BigInt(x * 256 ** (u8.length-1-i)) ) | |
| let res = "" | |
| while (1){ |
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 sortJSON = o => Object.fromEntries(Object.entries(o).sort((a,b)=>a[0].charCodeAt(0) - b[0].charCodeAt(0))) |
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
| /** | |
| * @example | |
| * html("div",{class:"hogehoge"},[ | |
| * html("p",{},"i am salmon!!"), | |
| * "<script>alert('raw html is not embeddable');</script>" | |
| * ]); | |
| */ | |
| const html = (name,attrs,...children) => ((children.length==1) && void(children[0] instanceof Array) && (children=children[0])) || {name:name,attrs:attrs,children:children,toString(){return `<${this.name} ${Object.entries(this.attrs).map(([k,v])=>(void(v=v.replace(/"|'|<|>/g,([c])=>"&x"+(c.charCodeAt(0).toString(16))+";")) || `${k}=${v?.match("'") ? '"'+v+'"' : v.match(/"|[\s]/) ? "'"+v+"'" : v}`)).join(" ")}>${children.map(x=>typeof x === "string" ? x.replace(/"|'|<|>/g,([c])=>"&#x"+(c.charCodeAt(0).toString(16))+";") : x.toString()).join("")}</${name}>`}} |
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 genChrs = (f,t)=>f<t ? String.fromCharCode(f++) + genChrs(f,t) : String.fromCharCode(f++) |
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
| /** | |
| * @example | |
| * console.log($enum("A","B","C"),$enum(10)("A","B","C")) // {A:0,B:1,C:2} {A:10,B:11,C:12} | |
| */ | |
| export function $enum(...start){ | |
| const mkobj=(...keys)=>Object.fromEntries(keys.map((x,i)=>[x,typeof start[0] === "number" ? start[0]+i : i])) | |
| return start.find(x=>typeof x !== "number") ? mkobj(...start) : mkobj | |
| } | |
| export default $enum; |
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
| Array.from({length:500},(_,n)=>((i=n+1)=>(i%3==0) + (i%15==0) + (i%5==0)*2)()).map((x,i)=>x&1 ? "Fizz" : x&2 ? "Buzz" : x&4 ? "Fizz Buzz" : i+1).forEach((m)=>console.log(m)) |