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 npmApiUrl = "https://api.npmjs.org/downloads/point"; | |
| async function fetchDownloadCounts(packageName, year) { | |
| let range = `${year}-01-01:${year}-12-31`; | |
| let response = await fetch(`${npmApiUrl}/${range}/${packageName}`); | |
| return (await response.json()).downloads; | |
| } | |
| async function getDownloads(startYear, endYear = startYear) { | |
| if (endYear < startYear) { |
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
| // Here is a function that I use all the time when creating public | |
| // async APIs in JavaScript: | |
| const resolvePromise = (promise, callback) => { | |
| if (callback) | |
| promise.then(value => callback(null, value), callback) | |
| return promise | |
| } | |
| // Sometimes I like to use callbacks, but other times a promise is |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>XML.js Test</title> | |
| <script type="text/javascript" src="xml.js"></script> | |
| <script type="text/javascript"> | |
| var xml = new XML('root'); | |
| xml.attr('one', 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
| var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; | |
| var shortDays = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]; | |
| var months = ["January","February","March","April","May","June","July","August","September","October","November","December"]; | |
| var shortMonths = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; | |
| function zeropad(n) { | |
| return n > 9 ? String(n) : "0" + String(n); | |
| } | |
| function twelveHour(t) { |
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
| // Event handling functions modified from originals by Dean Edwards. | |
| // http://dean.edwards.name/my/events.js | |
| var guid = 1; | |
| // Adds an event handler to the given element. The handler will be called | |
| // in the context of the element with the event object as its only argument. | |
| function addEvent(element, type, handler) { | |
| if (element.addEventListener) { | |
| element.addEventListener(type, handler, false); |
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
| // Returns the intersection of two sorted arrays of numbers or strings. | |
| function intersectArrays(a, b) { | |
| var array = [], ai = 0, alen = a.length, bi = 0, blen = b.length; | |
| while (ai < alen && bi < blen) { | |
| if (a[ai] < b[bi]) { | |
| ai++; | |
| } else if (a[ai] > b[bi]) { | |
| bi++; | |
| } else { |
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 util = require("util"), | |
| Stream = require("stream").Stream; | |
| module.exports = MockStream; | |
| /** | |
| * A constructor that inherits from Stream and emits data from the given | |
| * `source`. If it's a Stream it will be piped through to this stream. | |
| * Otherwise, it should be a string or a Buffer which will be emitted by this | |
| * stream as soon as possible. |
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 Firebase = require('firebase'); | |
| var baseRef = new Firebase('https://my-firebase.firebaseio.com'); | |
| function getSnapshotValue(snapshot) { | |
| return snapshot.val(); | |
| } | |
| /** | |
| * A mixin for components that want to bind the value of a state variable | |
| * to the value at a Firebase ref. |
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 d = require('d'); | |
| var warning = require('react/lib/warning'); | |
| var Promise = require('es6-promise').Promise; | |
| function isNotNull(object) { | |
| return object != null; | |
| } | |
| function Dispatcher() { | |
| this._currentActionName = 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
| var promise = new AbortablePromise(function (resolve, reject, onAbort) { | |
| // Use resolve & reject as you normally would. | |
| var request = makeRequest( ... , function (error, response) { | |
| if (error) { | |
| reject(error); | |
| } else { | |
| resolve(response); | |
| } | |
| }); |
NewerOlder