This file contains hidden or 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 OBJECT_TYPE = '[object Object]'; | |
| const TYPE_PROP = '__type__'; | |
| const VALUE_PROP = '__value__'; | |
| const jsParseMap = { | |
| '[object BigInt]': BigInt, | |
| }; | |
| const jsSerializeMap = { | |
| '[object BigInt]': (v) => `${v}`, |
This file contains hidden or 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 formatter = new Intl.DateTimeFormat('en-US', { | |
| year: 'numeric', | |
| month: '2-digit', | |
| day: '2-digit', | |
| hour: '2-digit', | |
| minute: '2-digit' | |
| }); | |
| function format(date: Date) { | |
| const mapParts = Object.create(null); |
This file contains hidden or 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 format(date: Date) { | |
| const formatter = new Intl.DateTimeFormat('en-US', { | |
| year: 'numeric', | |
| month: '2-digit', | |
| day: '2-digit', | |
| hour: '2-digit', | |
| minute: '2-digit' | |
| }); | |
| const mapParts = Object.create(null); | |
| const parts = formatter.formatToParts(date); |
This file contains hidden or 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 create = (() => { | |
| const handler = { | |
| get: (obj, property, reciever) => { | |
| if (!Reflect.has(obj, property)) { | |
| throw new ReferenceError(`Object has no property ${property}`); | |
| } | |
| return Reflect.get(obj, property); | |
| } | |
| }; |
This file contains hidden or 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 fromKeys(iterable, value) { | |
| let obj = {}; | |
| for (let i of iterable) { | |
| if (typeof value === 'function') { | |
| obj[i] = value(i) | |
| } | |
| else { | |
| obj[i] = value; | |
| } |
This file contains hidden or 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* merge(iterable1, iterable2) { | |
| let iter1 = iterable1[Symbol.iterator](); | |
| let iter2 = iterable2[Symbol.iterator](); | |
| let a = iter1.next(); | |
| let b = iter2.next(); | |
| let isFirst; | |
| while(!a.done && !b.done) { | |
| if (a.value <= b.value) { |
This file contains hidden or 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
| | | 1 2 3 | |
| | 1 | 2 3 | |
| | 1 2 | 3 | |
| | 1 2 3 | | |
| 1 | | 2 3 | |
| 1 | 2 | 3 | |
| 1 | 2 3 | | |
| 1 2 | | 3 | |
| 1 2 | 3 | | |
| 1 2 3 | | |
This file contains hidden or 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
| var pos = 0; | |
| window.addEventListener('scroll', function () { | |
| pos = document.body.scrollTop * (100 / document.body.scrollHeight) | |
| }) | |
| window.addEventListener('resize', function () { | |
| var scrollTop = pos * (document.body.scrollHeight / 100) | |
| window.scrollTo(0, scrollTop) | |
| }) |
This file contains hidden or 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
| var sort = (function () { | |
| function defCompare(a, b) { | |
| var aStr = String(a), | |
| bStr = String(b); | |
| if (aStr > bStr) { | |
| return 1; | |
| } | |
| else if (aStr < bStr) { | |
| return -1; |
This file contains hidden or 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
| switch(x) { | |
| case 1: | |
| //do something | |
| break; | |
| case 2: | |
| //do something | |
| break; | |
| } |
NewerOlder