Skip to content

Instantly share code, notes, and snippets.

View JCloudYu's full-sized avatar

JCloudYu JCloudYu

View GitHub Profile
@JCloudYu
JCloudYu / object-clone.js
Created December 20, 2018 18:12
Simple object deep cloning
const TYPED_ARRAYS = [ Uint8Array, Uint8ClampedArray, Int8Array, Uint16Array, Int16Array, Uint32Array, Int32Array, DataView ];
function ObjectClone(input, max_depth=128) {
const INPUT_TYPE = typeof input;
if ( INPUT_TYPE === null ||
INPUT_TYPE === undefined ||
INPUT_TYPE === "number" ||
INPUT_TYPE === "boolean" ||
INPUT_TYPE === "function" ||
@JCloudYu
JCloudYu / angularpromise.js
Created January 6, 2019 07:44 — forked from domenic/angularpromise.js
How to subclass a promise
// ES6
class AngularPromise extends Promise {
constructor(executor) {
super((resolve, reject) => {
// before
return executor(resolve, reject);
});
// after
}
@JCloudYu
JCloudYu / unit-test.js
Last active December 15, 2019 09:58
Standalone automatic unit test script for NodeJS environment.
/**
* Author: JCloudYu
* Create: 2019/02/06
**/
(async()=>{
let fs, path, dir, acquire;
if ( typeof require === "undefined" ) {
const {default:os} = await import( 'os' );
({default:fs} = await import( 'fs' ));
({default:path} = await import( 'path' ));
@JCloudYu
JCloudYu / njs-tasks.js
Last active May 27, 2019 08:20
A simple script that create a child node process that is based on specific node arguments
/**
* Author: JCloudYu
* Create: 2019/03/01
**/
(()=>{
"use strict";
const fs = require( 'fs' );
const path = require( 'path' );
@JCloudYu
JCloudYu / bootstrap.js
Last active September 2, 2020 13:11
The script load and boot the main script with es module mode enabled by default
/**
* ISC License
*
* Copyright (c) 2019, J. Cloud Yu
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
/**
* Author: JCloudYu
* Create: 2019/11/29
**/
const _PRIVATES = new WeakMap();
const configurable = true, writable = true, enumerable = false;
export const LogLevel = Object.freeze({
silent: -1,
error: 0,
/**
* Author: JCloudYu
* Create: 2019/07/16
**/
export const ColorCode = Object.freeze({
// region [ 8 Colors ]
RESET: "\u001b[39m",
BLACK: "\u001b[30m",
RED: "\u001b[31m",
GREEN: "\u001b[32m",
/**
* Author: JCloudYu
* Create: 2019/11/29
**/
const configurable = false, writable = false, enumerable = false;
export class ExtendedError extends Error {
constructor(info_obj, detail=null) {
super(info_obj.msg||'');
Object.defineProperties(this, {
_code: {value:info_obj.code, configurable, writable, enumerable},
/**
* Author: JCloudYu
* Create: 2019/12/14
**/
class _LocaleMap {
constructor(parent=null) {
this._locale_parent = parent;
this._locale = "_default";
this._locale_maps = Object.create(null);
this._locales = Object.create(null);
/**
* Author: ChenyChen, JCloudYu
* Create: 2020/01/29
**/
(async()=>{
"use strict";
const START_SIG = "//@export";
const START_SIG_LEN = START_SIG.length;
const END_SIG = "//@endexport";