Skip to content

Instantly share code, notes, and snippets.

@metaory
Last active September 28, 2024 13:07
Show Gist options
  • Save metaory/da3a27429e31907e299beb8722513c02 to your computer and use it in GitHub Desktop.
Save metaory/da3a27429e31907e299beb8722513c02 to your computer and use it in GitHub Desktop.
Utils for JS-Playground

PLAY JS UTILS

Utils for JS-Playground


Stability: 1 - Experimental

Caution

NOT FOR PRODUCTION!

 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄
 █▀▄▄▀█ ██ ▄▄▀█ ██ █  ████▄█ ▄▄█
 █ ▀▀ █ ██ ▀▀ █ ▀▀ █  ████ █▄▄▀█
 █ ████▄▄█▄██▄█▀▀▀▄█  ██ ▀ █▄▄▄█
 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀
  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  █ ██ █▄ ▄██▄██ ██ ▄▄█
  █ ██ ██ ███ ▄█ ██▄▄▀█
  ██▄▄▄██▄██▄▄▄█▄▄█▄▄▄█
  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Tip

Every thing is global


Installation

CLONE

git clone [email protected]:da3a27429e31907e299beb8722513c02.git play-js-utils

IMPORT

import './play-js-utils.mjs'

USE

◈ LINE SEPARATOR

Note

Number argument is ANSI 4-bit colors

Important

These are all valid usage

__()
__(2)
__(4)

__ >> _
__ >>> _
__ < _
;+__
__++
++__
~__

_1 >> _
_3 >> _
_4 <<< _
++_2
_l3 > _

◈ VAR LOG

l1('hi')
l2('heyy')
l3('hmm', { foo: 'bar' })
l4({ foo: 'bar', x11: 'xorg', x: [1, 22, 333] })
l5(foo, bar, 'bye')

License

Creative Commons License

const proxify = x =>
new Proxy(x, {
get() {
return x
},
})
const llen = () => process.stdout.columns - 12
const line = (n = 3, c = '─') => globalThis[`l${isNaN(n) ? 1 : n}`](c.repeat(llen()) + ' 􀯶')
Array.from({ length: 7 }).forEach((_, i) => {
globalThis[`l${i}`] = (...a) => {
const c = `\x1b[3${i}m`
process.stdout.write(`${c} 󰊹􀯻`)
a.forEach(x => {
const v = typeof x === 'object' ? JSON.stringify(x) : x
process.stdout.write('\x1b[30m')
process.stdout.write(' ⏽ ')
process.stdout.write(c)
process.stdout.write(v)
})
process.stdout.write('\x1b[0m\n')
}
globalThis[`_${i}`] = proxify(() => line(i))
})
globalThis.__ = proxify(line)
globalThis._ = proxify(() => {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment