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
/** | |
* @param {string} postCode post code | |
* @return {string|null} | |
* post code after an attempt converting to canonical format, | |
* in case conversion cannot be made, null will be returned. | |
*/ | |
function convertPostCode(postCode) { | |
if (!postCode || typeof postCode !== 'string') { | |
// postCode is null, undefined, or non string | |
return null; |
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
class RangeIterable { | |
constructor(start, end, step) { | |
this.start = start; | |
this.end = end; | |
this.step = step; | |
this.cnt = start; | |
} | |
[Symbol.iterator]() { | |
return this; |
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 Promise(func) { | |
var state = 'pending'; | |
var deferred = null; // the "then" handler | |
var value; | |
function resolve(newValue) { | |
state = 'resolved'; | |
value = newValue; | |
if (deferred) { | |
handle(deferred); |
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
// could be replaced by getBoundingClientRect() | |
function getDistanceToViewport(element: HTMLElement) { | |
let left = 0, top = 0, current: HTMLElement | |
current = element | |
while (current) { | |
left += current.offsetLeft | |
top += current.offsetTop | |
current = current.offsetParent as HTMLElement | |
} |
OlderNewer