This file contains 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 * as default from "./index.js"; | |
export * from "./index.js"; | |
// 1. write your lib in CommonJS | |
// 2. add "module": "index.mjs" to you package.json |
This file contains 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 obj = { | |
a: { | |
a: 5 | |
}, | |
b: { | |
a: 8 | |
} | |
}; | |
console.log(readGraph(obj, 'a.a')); // 5 |
This file contains 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
/** | |
* Usage: | |
* import callerProp from "./caller.js"; | |
* Object.defineProperty(global, "__caller", callerProp); | |
* | |
* function A() { | |
* return B(); | |
* } | |
* function B() { | |
* console.log(__caller.name); // A |
This file contains 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
/** | |
* Usage: | |
* Similar to native "Function.prototype.apply" but supporting an object as second argument. | |
* | |
* Given the following function: | |
* ``` | |
* function myFunction(a, b = 2, c = 3, options = {complex: true}) { | |
* console.log(a, b, c, options); | |
* } | |
* ``` |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Nano Stamp</title> | |
<style> | |
img { | |
image-rendering: pixelated; | |
border: 1px solid black; | |
} | |
</style> |
This file contains 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 const pipe = function<T>(promise: Promise<T>, ...callbacks: ((value: T) => T|Promise<T>)[]): Promise<T> { | |
let subject = promise; | |
for (const i in callbacks) { | |
subject = subject.then(callbacks[i]) | |
} | |
return subject; | |
} |
This file contains 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.prototype.flip = function() { | |
const obj = {}; | |
this.forEach((e, i) => { | |
obj[e] = i; | |
}); | |
return obj; | |
} |
This file contains 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
exports.unchain = function unchain(subject) { | |
const proxy = new Proxy(subject, { | |
get(target, name, receiver) { | |
if (name === '_') { | |
return new Proxy(subject, { | |
get(target, name, receiver) { | |
const member = Reflect.get(target, name, receiver); | |
if (typeof member === 'function') { | |
return function () { |
This file contains 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
<?php | |
function array_delete(&$array, $key) { | |
if (!isset($array[$key])) { | |
return null; | |
} | |
$value = $array[$key]; | |
unset($array[$key]); | |
return $value; | |
} |
This file contains 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 SEPARATOR = ':::'; | |
module.exports = (function() { | |
const cls = function() { | |
this.userVisits = {}; | |
}; | |
const parseSequences = function(userVisits, length) { | |
const sequences = {}; | |
const size = length - 1; |
NewerOlder