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
function pathfinder(needle, haystack, child = haystack, parent, result = [], path = [], paths = [[[haystack]]], siblingIndex = 0, depthIndex = 0, rootIndex, onRoot) { | |
let iterable = []; | |
if (Object.prototype.toString.call(child) === '[object Array]') { | |
iterable = child; | |
} else if (Object.prototype.toString.call(child) === '[object Object]') { | |
iterable = Object.keys(child); | |
} |
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'; | |
function deepsearch_find_first_object(needle, haystack, parent) { | |
let iterable; | |
if (Object.prototype.toString.call(haystack) === '[object Array]') { | |
iterable = haystack; | |
} else if (Object.prototype.toString.call(haystack) === '[object Object]') { | |
iterable = Object.keys(haystack); |
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'; | |
(() => { | |
class QuerySelector { | |
constructor(origin) { | |
/** | |
* :nth-of-type is only ie9+ https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type |
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 path = require('path'); | |
const express = require('express'); | |
const http = require('http'); | |
const io = require('socket.io'); | |
class Server { | |
constructor(config) { |
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 fs = require('fs'); | |
const path = require('path'); | |
const walkSync = (dir, filelist) => { | |
const files = fs.readdirSync(dir); | |
filelist = filelist || []; | |
files.forEach(function(file) { | |
if (fs.statSync(dir + '/' + file).isDirectory()) { |
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
// for HMR, don't add webpack/hot/devserver or whatever to config, just use --hot --inline in cli args | |
// https://github.com/webpack/webpack/issues/1151 | |
'use strict'; | |
const prod = /prod|production/i.test(process.env.NODE_ENV); | |
const webpack = require('webpack'); | |
const env = process.env.NODE_ENV; | |
const dev = /dev|development/i.test(env); | |
const prod = /prod|production/i.test(env); |
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 request = require('request-promise'); | |
const cheerio = require('cheerio'); | |
class Scraper { | |
constructor(opts) { | |
this.params = opts.params; | |
this.action = opts.action; |
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 webpack = require('webpack') | |
module.exports = { | |
devtool: 'inline-source-map', | |
entry: `${__dirname}/../src/index.js`, | |
output: { | |
publicPath: '/', |
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 pal = (s) => s | |
.split('') | |
.reduce((acc, c, head, arr) => Object.assign({}, acc, { | |
tail: acc.tail - 1, | |
result: (acc.result === false || arr[head] !== arr[acc.tail]) ? false : true | |
}), {result: null, tail: s.length - 1}) | |
.result |
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
import { parseFragment } from 'parse5' | |
const walk = (node = {}) => { | |
return (node.value || '') + (node.childNodes || []).reduce((child) => { | |
return walk(child) | |
}) | |
} | |
export default (htmlStr) => [parseFragment(htmlStr)].reduce(walk) |