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
/** | |
* Add a 'pre' tag, with a specified id, to the page and log the arguments passed to it | |
* | |
* WIP: | |
* - support array & object deep log | |
* - option to log in console (last parameter) | |
*/ | |
function documentLog (...arg) { | |
if (!arg || !arg.length) return | |
if (!((typeof arg[0]) === 'string')) return |
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
/** | |
* Watch for object properties | |
* you can log on each property change and even add a breakpoint | |
*/ | |
function consoleWatch (oObj, sProp) { | |
let sPrivateProp = `_${sProp}_$` | |
oObj[sPrivateProp] = oObj[sProp] | |
Object.defineProperty(oObj, sProp, { | |
get: () => { return oObj[sPrivateProp] }, | |
set: 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
/** | |
* This is a proxy for making w3c compliant requests to the EPITECH's BLIH API. | |
* It allows to make such calls fron any w3c compliant source (e.g. XHR requests). | |
* The proxy uses https for security reasons. | |
* To check BLIH API status simply make a GET request on '/'. | |
* | |
* TODO: | |
* - Add endpoint showing every endpoint available (API documentation). | |
*/ |
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
/** | |
* Run a simple check on every attribute of an object | |
* It returns true if any attribute (non object) passes the test function | |
*/ | |
function checkDeep(obj, fun) { | |
for (let k in obj) { | |
if (!obj.hasOwnProperty(k)) continue | |
if (Array.isArray(obj[k])) { | |
if (obj[k].some(fun)) |
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
/** | |
* Simple durations stringifier for Moment.js | |
* Return a human readable string representing the given moment duration | |
* Based on @cogwirrel comment (https://github.com/moment/moment/issues/348#issuecomment-346233713) | |
* | |
* TODO: | |
* - Add simple lang support (fr, en) | |
*/ | |
function stringifyDuration (duration) { |
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
'use strict'; | |
const parseMs = require('parse-ms'); | |
const plur = require('plur'); | |
const units = [{ s: 'y', l: 'year' }, | |
{ s: 'd', l: 'day' }, | |
{ s: 'h', l: 'hour' }, | |
{ s: 'm', l: 'minute' }, | |
{ s: 's', l: 'second' }, | |
{ s: 'ms', l: 'millisecond' }]; |
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
/** | |
* Simple logging on an observable, without altering the subscription. | |
* | |
* @param {Observable<any>} obs - Observable (RxJS) | |
* @param success - success message | |
* @param failure - error message | |
* @returns {Observable<any>} | |
*/ | |
function logObservable (obs, success, failure) { | |
if (success) { |
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
/** | |
* Pick the specified properties of an object | |
* | |
* @param obj | |
* @param {Array<Array<string> | string>} keys | |
* @returns {{}} | |
*/ | |
function pick (obj, keys) { | |
return keys.reduce((sum, k) => (Array.isArray(k) ? sum[k[1]] = obj[k[0]] : sum[k] = obj[k], sum), {}) | |
} |
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 http = require('http') | |
const url = require('url') | |
const path = require('path') | |
const fs = require('fs') | |
const PORT = parseInt(process.argv[2]) || 8888 | |
http.createServer(function(req, res) { | |
const uri = url.parse(req.url).pathname | |
const filename = path.join(process.cwd(), uri) |
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
let obj = { a: 'a', b: null, undefined: 'undef', null: 'nil' } | |
obj['a'] // 'a' | |
obj[obj.b] // 'nil' | |
obj[obj.c] // 'undef' (obj.c is undefined) | |
obj[obj] // undefined | |
// Can be used for making conditions with objects |
OlderNewer