var url = '/product/shoes/234'
var regex = '/(product|:[a-zA-Z0-9]+)/(shoes|:[a-zA-Z0-9]+)/(234|:[a-zA-Z0-9+)'
html { | |
-webkit-font-smoothing: antialiased; | |
} | |
body { | |
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif; | |
line-height: 1.5; | |
} | |
h1, h2, h3, h4, h5, h6 { |
var DI = function () { | |
let _deps = {} | |
this.dep = (name, func) => { _deps[name] = func } | |
this.getDep = (name) => _deps[name] | |
} | |
DI.prototype.inject = function (fn) { | |
let fnString = fn.toString().replace(/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg, ''), | |
paramNames = fnString.split('(')[1].split(')')[0].split(',').map(v => v.trim()), |
/** | |
* Creates an object of groupings. | |
* | |
* @param {Function|String} f - The function that returns value to group by or object key. | |
* @returns {Object} Returns the composed aggregate object. | |
* @example | |
* | |
* array.groupBy('city'); | |
* array.groupBy(function (obj) { return obj.city; }); | |
* array.groupBy((obj) => { return obj.city; }); |
const getNthHamming = n => getHammingNumbers(n).reverse()[0] | |
const getHammingNumbers = n => { | |
let numbers = [] | |
let next = 1 | |
while (numbers.length < n) { | |
if (isHammingNumber(next)) | |
numbers.push(next) | |
const multilevelsort = (records, order) => records.sort(chainSortBy(order)) | |
const sort_by = ({ key, direction }) => { | |
return function (a, b) { | |
a = a[key] | |
b = b[key] | |
return a == b ? 0 : [-1, 1][+(direction === 'ascending')] * ((a > b) - (b > a)) | |
} | |
} |
Array.prototype.transpose = function () { | |
return this.length === 0 ? this : this[0].map((col, i) => this.map((row) => row[i])) | |
} |
article { | |
h1, h2, h3, h4, h5, h6, img, ul, ol { margin-bottom: 20px; } | |
h1 { font-size: 2em; line-height: 1.5; } | |
h2 { font-size: 1.5em; line-height: 1.5; } | |
h3 { font-size: 1.17em; line-height: 1.5; } | |
h4 { font-size: 1em; line-height: 1.5; } | |
h5 { font-size: 0.83em; line-height: 1.5; } | |
h6 { font-size: 0.67em; line-height: 1.5; } | |
strong { font-weight: bold; } | |
img { display: block; max-width: 100%; margin-bottom: 20px; } |
new Promise(function (reject) { | |
}).then(function (reject) { | |
reject('this is an error'); | |
}).then(function () { | |
console.log('never run'); | |
}).catch(function (err) { | |
console.log('err', err); | |
}).finally(function () { |
events.publish('/page/load', { | |
url: '/some/url/path' // any argument | |
}); | |
var subscription = events.subscribe('/page/load', function(obj) { | |
// Do something now that the event has occurred | |
}); | |
// ...sometime later where I no longer want subscription... | |
subscription.remove(); |