Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,119 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
var invariant = require('./invariant');
/**
* The CSSCore module specifies the API (and implements most of the methods)
* that should be used when dealing with the display of elements (via their
* CSS classes and visibility on screen. It is an API focused on mutating the
* display and not reading it as no logical state should be encoded in the
* display of elements.
*/
/* Slow implementation for browsers that don't natively support .matches() */
function matchesSelector_SLOW(element, selector) {
var root = element;
while (root.parentNode) {
root = root.parentNode;
}
var all = root.querySelectorAll(selector);
return Array.prototype.indexOf.call(all, element) !== -1;
}
var CSSCore = {
/**
* Adds the class passed in to the element if it doesn't already have it.
*
* @param {DOMElement} element the element to set the class on
* @param {string} className the CSS className
* @return {DOMElement} the element passed in
*/
addClass: function addClass(element, className) {
!!/\s/.test(className) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'CSSCore.addClass takes only a single class name. "%s" contains ' + 'multiple classes.', className) : invariant(false) : void 0;
if (className) {
if (element.classList) {
element.classList.add(className);
} else if (!CSSCore.hasClass(element, className)) {
element.className = element.className + ' ' + className;
}
}
return element;
},
/**
* Removes the class passed in from the element
*
* @param {DOMElement} element the element to set the class on
* @param {string} className the CSS className
* @return {DOMElement} the element passed in
*/
removeClass: function removeClass(element, className) {
!!/\s/.test(className) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'CSSCore.removeClass takes only a single class name. "%s" contains ' + 'multiple classes.', className) : invariant(false) : void 0;
if (className) {
if (element.classList) {
element.classList.remove(className);
} else if (CSSCore.hasClass(element, className)) {
element.className = element.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)', 'g'), '$1').replace(/\s+/g, ' ') // multiple spaces to one
.replace(/^\s*|\s*$/g, ''); // trim the ends
}
}
return element;
},
/**
* Helper to add or remove a class from an element based on a condition.
*
* @param {DOMElement} element the element to set the class on
* @param {string} className the CSS className
* @param {*} bool condition to whether to add or remove the class
* @return {DOMElement} the element passed in
*/
conditionClass: function conditionClass(element, className, bool) {
return (bool ? CSSCore.addClass : CSSCore.removeClass)(element, className);
},
/**
* Tests whether the element has the class specified.
*
* @param {DOMNode|DOMWindow} element the element to check the class on
* @param {string} className the CSS className
* @return {boolean} true if the element has the class, false if not
*/
hasClass: function hasClass(element, className) {
!!/\s/.test(className) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'CSS.hasClass takes only a single class name.') : invariant(false) : void 0;
if (element.classList) {
return !!className && element.classList.contains(className);
}
return (' ' + element.className + ' ').indexOf(' ' + className + ' ') > -1;
},
/**
* Tests whether the element matches the selector specified
*
* @param {DOMNode|DOMWindow} element the element that we are querying
* @param {string} selector the CSS selector
* @return {boolean} true if the element matches the selector, false if not
*/
matchesSelector: function matchesSelector(element, selector) {
var matchesImpl = element.matches || element.webkitMatchesSelector || element.mozMatchesSelector || element.msMatchesSelector || function (s) {
return matchesSelector_SLOW(element, s);
};
return matchesImpl.call(element, selector);
}
};
module.exports = CSSCore;

View File

@@ -0,0 +1,116 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule CSSCore
* @typechecks
*/
const invariant = require('./invariant');
/**
* The CSSCore module specifies the API (and implements most of the methods)
* that should be used when dealing with the display of elements (via their
* CSS classes and visibility on screen. It is an API focused on mutating the
* display and not reading it as no logical state should be encoded in the
* display of elements.
*/
/* Slow implementation for browsers that don't natively support .matches() */
function matchesSelector_SLOW(element, selector) {
let root = element;
while (root.parentNode) {
root = root.parentNode;
}
const all = root.querySelectorAll(selector);
return Array.prototype.indexOf.call(all, element) !== -1;
}
const CSSCore = {
/**
* Adds the class passed in to the element if it doesn't already have it.
*
* @param {DOMElement} element the element to set the class on
* @param {string} className the CSS className
* @return {DOMElement} the element passed in
*/
addClass: function (element, className) {
invariant(!/\s/.test(className), 'CSSCore.addClass takes only a single class name. "%s" contains ' + 'multiple classes.', className);
if (className) {
if (element.classList) {
element.classList.add(className);
} else if (!CSSCore.hasClass(element, className)) {
element.className = element.className + ' ' + className;
}
}
return element;
},
/**
* Removes the class passed in from the element
*
* @param {DOMElement} element the element to set the class on
* @param {string} className the CSS className
* @return {DOMElement} the element passed in
*/
removeClass: function (element, className) {
invariant(!/\s/.test(className), 'CSSCore.removeClass takes only a single class name. "%s" contains ' + 'multiple classes.', className);
if (className) {
if (element.classList) {
element.classList.remove(className);
} else if (CSSCore.hasClass(element, className)) {
element.className = element.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)', 'g'), '$1').replace(/\s+/g, ' ') // multiple spaces to one
.replace(/^\s*|\s*$/g, ''); // trim the ends
}
}
return element;
},
/**
* Helper to add or remove a class from an element based on a condition.
*
* @param {DOMElement} element the element to set the class on
* @param {string} className the CSS className
* @param {*} bool condition to whether to add or remove the class
* @return {DOMElement} the element passed in
*/
conditionClass: function (element, className, bool) {
return (bool ? CSSCore.addClass : CSSCore.removeClass)(element, className);
},
/**
* Tests whether the element has the class specified.
*
* @param {DOMNode|DOMWindow} element the element to check the class on
* @param {string} className the CSS className
* @return {boolean} true if the element has the class, false if not
*/
hasClass: function (element, className) {
invariant(!/\s/.test(className), 'CSS.hasClass takes only a single class name.');
if (element.classList) {
return !!className && element.classList.contains(className);
}
return (' ' + element.className + ' ').indexOf(' ' + className + ' ') > -1;
},
/**
* Tests whether the element matches the selector specified
*
* @param {DOMNode|DOMWindow} element the element that we are querying
* @param {string} selector the CSS selector
* @return {boolean} true if the element matches the selector, false if not
*/
matchesSelector: function (element, selector) {
const matchesImpl = element.matches || element.webkitMatchesSelector || element.mozMatchesSelector || element.msMatchesSelector || (s => matchesSelector_SLOW(element, s));
return matchesImpl.call(element, selector);
}
};
module.exports = CSSCore;

View File

@@ -0,0 +1,219 @@
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
var PhotosMimeType = require('./PhotosMimeType');
var createArrayFromMixed = require('./createArrayFromMixed');
var emptyFunction = require('./emptyFunction');
var CR_LF_REGEX = new RegExp('\r\n', 'g');
var LF_ONLY = '\n';
var RICH_TEXT_TYPES = {
'text/rtf': 1,
'text/html': 1
};
/**
* If DataTransferItem is a file then return the Blob of data.
*
* @param {object} item
* @return {?blob}
*/
function getFileFromDataTransfer(item) {
if (item.kind == 'file') {
return item.getAsFile();
}
}
var DataTransfer = function () {
/**
* @param {object} data
*/
function DataTransfer(data) {
_classCallCheck(this, DataTransfer);
this.data = data;
// Types could be DOMStringList or array
this.types = data.types ? createArrayFromMixed(data.types) : [];
}
/**
* Is this likely to be a rich text data transfer?
*
* @return {boolean}
*/
DataTransfer.prototype.isRichText = function isRichText() {
// If HTML is available, treat this data as rich text. This way, we avoid
// using a pasted image if it is packaged with HTML -- this may occur with
// pastes from MS Word, for example. However this is only rich text if
// there's accompanying text.
if (this.getHTML() && this.getText()) {
return true;
}
// When an image is copied from a preview window, you end up with two
// DataTransferItems one of which is a file's metadata as text. Skip those.
if (this.isImage()) {
return false;
}
return this.types.some(function (type) {
return RICH_TEXT_TYPES[type];
});
};
/**
* Get raw text.
*
* @return {?string}
*/
DataTransfer.prototype.getText = function getText() {
var text;
if (this.data.getData) {
if (!this.types.length) {
text = this.data.getData('Text');
} else if (this.types.indexOf('text/plain') != -1) {
text = this.data.getData('text/plain');
}
}
return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
};
/**
* Get HTML paste data
*
* @return {?string}
*/
DataTransfer.prototype.getHTML = function getHTML() {
if (this.data.getData) {
if (!this.types.length) {
return this.data.getData('Text');
} else if (this.types.indexOf('text/html') != -1) {
return this.data.getData('text/html');
}
}
};
/**
* Is this a link data transfer?
*
* @return {boolean}
*/
DataTransfer.prototype.isLink = function isLink() {
return this.types.some(function (type) {
return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
});
};
/**
* Get a link url.
*
* @return {?string}
*/
DataTransfer.prototype.getLink = function getLink() {
if (this.data.getData) {
if (this.types.indexOf('text/x-moz-url') != -1) {
var url = this.data.getData('text/x-moz-url').split('\n');
return url[0];
}
return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
}
return null;
};
/**
* Is this an image data transfer?
*
* @return {boolean}
*/
DataTransfer.prototype.isImage = function isImage() {
var isImage = this.types.some(function (type) {
// Firefox will have a type of application/x-moz-file for images during
// dragging
return type.indexOf('application/x-moz-file') != -1;
});
if (isImage) {
return true;
}
var items = this.getFiles();
for (var i = 0; i < items.length; i++) {
var type = items[i].type;
if (!PhotosMimeType.isImage(type)) {
return false;
}
}
return true;
};
DataTransfer.prototype.getCount = function getCount() {
if (this.data.hasOwnProperty('items')) {
return this.data.items.length;
} else if (this.data.hasOwnProperty('mozItemCount')) {
return this.data.mozItemCount;
} else if (this.data.files) {
return this.data.files.length;
}
return null;
};
/**
* Get files.
*
* @return {array}
*/
DataTransfer.prototype.getFiles = function getFiles() {
if (this.data.items) {
// createArrayFromMixed doesn't properly handle DataTransferItemLists.
return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction.thatReturnsArgument);
} else if (this.data.files) {
return Array.prototype.slice.call(this.data.files);
} else {
return [];
}
};
/**
* Are there any files to fetch?
*
* @return {boolean}
*/
DataTransfer.prototype.hasFiles = function hasFiles() {
return this.getFiles().length > 0;
};
return DataTransfer;
}();
module.exports = DataTransfer;

View File

@@ -0,0 +1,194 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule DataTransfer
* @typechecks
*/
var PhotosMimeType = require('./PhotosMimeType');
var createArrayFromMixed = require('./createArrayFromMixed');
var emptyFunction = require('./emptyFunction');
var CR_LF_REGEX = new RegExp('\u000D\u000A', 'g');
var LF_ONLY = '\u000A';
var RICH_TEXT_TYPES = {
'text/rtf': 1,
'text/html': 1
};
/**
* If DataTransferItem is a file then return the Blob of data.
*
* @param {object} item
* @return {?blob}
*/
function getFileFromDataTransfer(item) {
if (item.kind == 'file') {
return item.getAsFile();
}
}
class DataTransfer {
/**
* @param {object} data
*/
constructor(data) {
this.data = data;
// Types could be DOMStringList or array
this.types = data.types ? createArrayFromMixed(data.types) : [];
}
/**
* Is this likely to be a rich text data transfer?
*
* @return {boolean}
*/
isRichText() {
// If HTML is available, treat this data as rich text. This way, we avoid
// using a pasted image if it is packaged with HTML -- this may occur with
// pastes from MS Word, for example. However this is only rich text if
// there's accompanying text.
if (this.getHTML() && this.getText()) {
return true;
}
// When an image is copied from a preview window, you end up with two
// DataTransferItems one of which is a file's metadata as text. Skip those.
if (this.isImage()) {
return false;
}
return this.types.some(type => RICH_TEXT_TYPES[type]);
}
/**
* Get raw text.
*
* @return {?string}
*/
getText() {
var text;
if (this.data.getData) {
if (!this.types.length) {
text = this.data.getData('Text');
} else if (this.types.indexOf('text/plain') != -1) {
text = this.data.getData('text/plain');
}
}
return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
}
/**
* Get HTML paste data
*
* @return {?string}
*/
getHTML() {
if (this.data.getData) {
if (!this.types.length) {
return this.data.getData('Text');
} else if (this.types.indexOf('text/html') != -1) {
return this.data.getData('text/html');
}
}
}
/**
* Is this a link data transfer?
*
* @return {boolean}
*/
isLink() {
return this.types.some(type => {
return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
});
}
/**
* Get a link url.
*
* @return {?string}
*/
getLink() {
if (this.data.getData) {
if (this.types.indexOf('text/x-moz-url') != -1) {
let url = this.data.getData('text/x-moz-url').split('\n');
return url[0];
}
return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
}
return null;
}
/**
* Is this an image data transfer?
*
* @return {boolean}
*/
isImage() {
var isImage = this.types.some(type => {
// Firefox will have a type of application/x-moz-file for images during
// dragging
return type.indexOf('application/x-moz-file') != -1;
});
if (isImage) {
return true;
}
var items = this.getFiles();
for (var i = 0; i < items.length; i++) {
var type = items[i].type;
if (!PhotosMimeType.isImage(type)) {
return false;
}
}
return true;
}
getCount() {
if (this.data.hasOwnProperty('items')) {
return this.data.items.length;
} else if (this.data.hasOwnProperty('mozItemCount')) {
return this.data.mozItemCount;
} else if (this.data.files) {
return this.data.files.length;
}
return null;
}
/**
* Get files.
*
* @return {array}
*/
getFiles() {
if (this.data.items) {
// createArrayFromMixed doesn't properly handle DataTransferItemLists.
return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction.thatReturnsArgument);
} else if (this.data.files) {
return Array.prototype.slice.call(this.data.files);
} else {
return [];
}
}
/**
* Are there any files to fetch?
*
* @return {boolean}
*/
hasFiles() {
return this.getFiles().length > 0;
}
}
module.exports = DataTransfer;

View File

@@ -0,0 +1,79 @@
"use strict";
var Promise = require("./Promise");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*
*/
/**
* Deferred provides a Promise-like API that exposes methods to resolve and
* reject the Promise. It is most useful when converting non-Promise code to use
* Promises.
*
* If you want to export the Promise without exposing access to the resolve and
* reject methods, you should export `getPromise` which returns a Promise with
* the same semantics excluding those methods.
*/
var Deferred = function () {
function Deferred() {
var _this = this;
_classCallCheck(this, Deferred);
this._settled = false;
this._promise = new Promise(function (resolve, reject) {
_this._resolve = resolve;
_this._reject = reject;
});
}
Deferred.prototype.getPromise = function getPromise() {
return this._promise;
};
Deferred.prototype.resolve = function resolve(value) {
this._settled = true;
this._resolve(value);
};
Deferred.prototype.reject = function reject(reason) {
this._settled = true;
this._reject(reason);
};
Deferred.prototype["catch"] = function _catch(onReject) {
return Promise.prototype["catch"].apply(this._promise, arguments);
};
Deferred.prototype.then = function then(onFulfill, onReject) {
return Promise.prototype.then.apply(this._promise, arguments);
};
Deferred.prototype.done = function done(onFulfill, onReject) {
// Embed the polyfill for the non-standard Promise.prototype.done so that
// users of the open source fbjs don't need a custom lib for Promise
var promise = arguments.length ? this._promise.then.apply(this._promise, arguments) : this._promise;
promise.then(undefined, function (err) {
setTimeout(function () {
throw err;
}, 0);
});
};
Deferred.prototype.isSettled = function isSettled() {
return this._settled;
};
return Deferred;
}();
module.exports = Deferred;

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule Deferred
* @typechecks
* @flow
*/
/**
* Deferred provides a Promise-like API that exposes methods to resolve and
* reject the Promise. It is most useful when converting non-Promise code to use
* Promises.
*
* If you want to export the Promise without exposing access to the resolve and
* reject methods, you should export `getPromise` which returns a Promise with
* the same semantics excluding those methods.
*/
class Deferred<Tvalue, Treason> {
_settled: boolean;
_promise: Promise<any>;
_resolve: (value: Tvalue) => void;
_reject: (reason: Treason) => void;
constructor() {
this._settled = false;
this._promise = new Promise((resolve, reject) => {
this._resolve = (resolve: any);
this._reject = (reject: any);
});
}
getPromise(): Promise<any> {
return this._promise;
}
resolve(value: Tvalue): void {
this._settled = true;
this._resolve(value);
}
reject(reason: Treason): void {
this._settled = true;
this._reject(reason);
}
catch(onReject?: ?(error: any) => mixed): Promise<any> {
return Promise.prototype.catch.apply(this._promise, arguments);
}
then(onFulfill?: ?(value: any) => mixed, onReject?: ?(error: any) => mixed): Promise<any> {
return Promise.prototype.then.apply(this._promise, arguments);
}
done(onFulfill?: ?(value: any) => mixed, onReject?: ?(error: any) => mixed): void {
// Embed the polyfill for the non-standard Promise.prototype.done so that
// users of the open source fbjs don't need a custom lib for Promise
const promise = arguments.length ? this._promise.then.apply(this._promise, arguments) : this._promise;
promise.then(undefined, function (err) {
setTimeout(function () {
throw err;
}, 0);
});
}
isSettled(): boolean {
return this._settled;
}
}
module.exports = Deferred;

View File

@@ -0,0 +1,26 @@
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/* jslint unused:false */
if (global.ErrorUtils) {
module.exports = global.ErrorUtils;
} else {
var ErrorUtils = {
applyWithGuard: function applyWithGuard(callback, context, args, onError, name) {
return callback.apply(context, args);
},
guard: function guard(callback, name) {
return callback;
}
};
module.exports = ErrorUtils;
}

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule ErrorUtils
*/
/* jslint unused:false */
if (global.ErrorUtils) {
module.exports = global.ErrorUtils;
} else {
var ErrorUtils = {
applyWithGuard(callback, context, args, onError, name) {
return callback.apply(context, args);
},
guard(callback, name) {
return callback;
}
};
module.exports = ErrorUtils;
}

View File

@@ -0,0 +1,74 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
var emptyFunction = require('./emptyFunction');
/**
* Upstream version of event listener. Does not take into account specific
* nature of platform.
*/
var EventListener = {
/**
* Listen to DOM events during the bubble phase.
*
* @param {DOMEventTarget} target DOM element to register listener on.
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
* @param {function} callback Callback function.
* @return {object} Object with a `remove` method.
*/
listen: function listen(target, eventType, callback) {
if (target.addEventListener) {
target.addEventListener(eventType, callback, false);
return {
remove: function remove() {
target.removeEventListener(eventType, callback, false);
}
};
} else if (target.attachEvent) {
target.attachEvent('on' + eventType, callback);
return {
remove: function remove() {
target.detachEvent('on' + eventType, callback);
}
};
}
},
/**
* Listen to DOM events during the capture phase.
*
* @param {DOMEventTarget} target DOM element to register listener on.
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
* @param {function} callback Callback function.
* @return {object} Object with a `remove` method.
*/
capture: function capture(target, eventType, callback) {
if (target.addEventListener) {
target.addEventListener(eventType, callback, true);
return {
remove: function remove() {
target.removeEventListener(eventType, callback, true);
}
};
} else {
if (process.env.NODE_ENV !== 'production') {
console.error('Attempted to listen to events during the capture phase on a ' + 'browser that does not support the capture phase. Your application ' + 'will not receive some events.');
}
return {
remove: emptyFunction
};
}
},
registerDefault: function registerDefault() {}
};
module.exports = EventListener;

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule EventListener
* @typechecks
*/
var emptyFunction = require('./emptyFunction');
/**
* Upstream version of event listener. Does not take into account specific
* nature of platform.
*/
var EventListener = {
/**
* Listen to DOM events during the bubble phase.
*
* @param {DOMEventTarget} target DOM element to register listener on.
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
* @param {function} callback Callback function.
* @return {object} Object with a `remove` method.
*/
listen: function (target, eventType, callback) {
if (target.addEventListener) {
target.addEventListener(eventType, callback, false);
return {
remove: function () {
target.removeEventListener(eventType, callback, false);
}
};
} else if (target.attachEvent) {
target.attachEvent('on' + eventType, callback);
return {
remove: function () {
target.detachEvent('on' + eventType, callback);
}
};
}
},
/**
* Listen to DOM events during the capture phase.
*
* @param {DOMEventTarget} target DOM element to register listener on.
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
* @param {function} callback Callback function.
* @return {object} Object with a `remove` method.
*/
capture: function (target, eventType, callback) {
if (target.addEventListener) {
target.addEventListener(eventType, callback, true);
return {
remove: function () {
target.removeEventListener(eventType, callback, true);
}
};
} else {
if (__DEV__) {
console.error('Attempted to listen to events during the capture phase on a ' + 'browser that does not support the capture phase. Your application ' + 'will not receive some events.');
}
return {
remove: emptyFunction
};
}
},
registerDefault: function () {}
};
module.exports = EventListener;

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
/**
* Simple, lightweight module assisting with the detection and context of
* Worker. Helps avoid circular dependencies and allows code to reason about
* whether or not they are in a Worker, even if they never include the main
* `ReactWorker` dependency.
*/
var ExecutionEnvironment = {
canUseDOM: canUseDOM,
canUseWorkers: typeof Worker !== 'undefined',
canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent),
canUseViewport: canUseDOM && !!window.screen,
isInWorker: !canUseDOM // For now, this is true - might change in the future.
};
module.exports = ExecutionEnvironment;

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule ExecutionEnvironment
*/
'use strict';
const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
/**
* Simple, lightweight module assisting with the detection and context of
* Worker. Helps avoid circular dependencies and allows code to reason about
* whether or not they are in a Worker, even if they never include the main
* `ReactWorker` dependency.
*/
const ExecutionEnvironment = {
canUseDOM: canUseDOM,
canUseWorkers: typeof Worker !== 'undefined',
canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent),
canUseViewport: canUseDOM && !!window.screen,
isInWorker: !canUseDOM // For now, this is true - might change in the future.
};
module.exports = ExecutionEnvironment;

View File

@@ -0,0 +1,34 @@
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
module.exports = {
BACKSPACE: 8,
TAB: 9,
RETURN: 13,
ALT: 18,
ESC: 27,
SPACE: 32,
PAGE_UP: 33,
PAGE_DOWN: 34,
END: 35,
HOME: 36,
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40,
DELETE: 46,
COMMA: 188,
PERIOD: 190,
A: 65,
Z: 90,
ZERO: 48,
NUMPAD_0: 96,
NUMPAD_9: 105
};

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule Keys
*/
module.exports = {
BACKSPACE: 8,
TAB: 9,
RETURN: 13,
ALT: 18,
ESC: 27,
SPACE: 32,
PAGE_UP: 33,
PAGE_DOWN: 34,
END: 35,
HOME: 36,
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40,
DELETE: 46,
COMMA: 188,
PERIOD: 190,
A: 65,
Z: 90,
ZERO: 48,
NUMPAD_0: 96,
NUMPAD_9: 105
};

View File

@@ -0,0 +1,11 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
module.exports = require('core-js/library/es6/map');

View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule Map
*/
module.exports = require('core-js/library/es6/map');

View File

@@ -0,0 +1,26 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
var PhotosMimeType = {
isImage: function isImage(mimeString) {
return getParts(mimeString)[0] === 'image';
},
isJpeg: function isJpeg(mimeString) {
var parts = getParts(mimeString);
return PhotosMimeType.isImage(mimeString) && (
// see http://fburl.com/10972194
parts[1] === 'jpeg' || parts[1] === 'pjpeg');
}
};
function getParts(mimeString) {
return mimeString.split('/');
}
module.exports = PhotosMimeType;

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule PhotosMimeType
*/
const PhotosMimeType = {
isImage(mimeString) {
return getParts(mimeString)[0] === 'image';
},
isJpeg(mimeString) {
const parts = getParts(mimeString);
return PhotosMimeType.isImage(mimeString) && (
// see http://fburl.com/10972194
parts[1] === 'jpeg' || parts[1] === 'pjpeg');
}
};
function getParts(mimeString) {
return mimeString.split('/');
}
module.exports = PhotosMimeType;

View File

@@ -0,0 +1,11 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
module.exports = require('promise');

View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule Promise
*/
module.exports = require('promise');

View File

@@ -0,0 +1,25 @@
/**
*
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* This module wraps and augments the minimally ES6-compliant Promise
* implementation provided by the promise npm package.
*
*/
'use strict';
var Promise = require('promise/setimmediate/es6-extensions');
require('promise/setimmediate/done');
/**
* Handle either fulfillment or rejection with the same callback.
*/
Promise.prototype['finally'] = function (onSettled) {
return this.then(onSettled, onSettled);
};
module.exports = Promise;

View File

@@ -0,0 +1,25 @@
/**
*
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* This module wraps and augments the minimally ES6-compliant Promise
* implementation provided by the promise npm package.
*
*/
'use strict';
var Promise = require('promise/setimmediate/es6-extensions');
require('promise/setimmediate/done');
/**
* Handle either fulfillment or rejection with the same callback.
*/
Promise.prototype.finally = function (onSettled) {
return this.then(onSettled, onSettled);
};
module.exports = Promise;

View File

@@ -0,0 +1,57 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Deferred = require('./Deferred');
var invariant = require('./invariant');
/**
* A map of asynchronous values that can be get or set in any order. Unlike a
* normal map, setting the value for a particular key more than once throws.
* Also unlike a normal map, a key can either be resolved or rejected.
*/
var PromiseMap = function () {
function PromiseMap() {
_classCallCheck(this, PromiseMap);
this._deferred = {};
}
PromiseMap.prototype.get = function get(key) {
return getDeferred(this._deferred, key).getPromise();
};
PromiseMap.prototype.resolveKey = function resolveKey(key, value) {
var entry = getDeferred(this._deferred, key);
!!entry.isSettled() ? process.env.NODE_ENV !== 'production' ? invariant(false, 'PromiseMap: Already settled `%s`.', key) : invariant(false) : void 0;
entry.resolve(value);
};
PromiseMap.prototype.rejectKey = function rejectKey(key, reason) {
var entry = getDeferred(this._deferred, key);
!!entry.isSettled() ? process.env.NODE_ENV !== 'production' ? invariant(false, 'PromiseMap: Already settled `%s`.', key) : invariant(false) : void 0;
entry.reject(reason);
};
return PromiseMap;
}();
function getDeferred(entries, key) {
if (!entries.hasOwnProperty(key)) {
entries[key] = new Deferred();
}
return entries[key];
}
module.exports = PromiseMap;

View File

@@ -0,0 +1,53 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule PromiseMap
* @flow
*/
'use strict';
const Deferred = require('./Deferred');
const invariant = require('./invariant');
/**
* A map of asynchronous values that can be get or set in any order. Unlike a
* normal map, setting the value for a particular key more than once throws.
* Also unlike a normal map, a key can either be resolved or rejected.
*/
class PromiseMap<Tvalue, Treason> {
_deferred: { [key: string]: Deferred<any, any> };
constructor() {
this._deferred = {};
}
get(key: string): Promise<any> {
return getDeferred(this._deferred, key).getPromise();
}
resolveKey(key: string, value: Tvalue): void {
const entry = getDeferred(this._deferred, key);
invariant(!entry.isSettled(), 'PromiseMap: Already settled `%s`.', key);
entry.resolve(value);
}
rejectKey(key: string, reason: Treason): void {
const entry = getDeferred(this._deferred, key);
invariant(!entry.isSettled(), 'PromiseMap: Already settled `%s`.', key);
entry.reject(reason);
}
}
function getDeferred(entries: { [key: string]: Deferred<any, any> }, key: string): Deferred<any, any> {
if (!entries.hasOwnProperty(key)) {
entries[key] = new Deferred();
}
return entries[key];
}
module.exports = PromiseMap;

View File

@@ -0,0 +1,83 @@
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/**
* @param {DOMElement} element
* @param {DOMDocument} doc
* @return {boolean}
*/
function _isViewportScrollElement(element, doc) {
return !!doc && (element === doc.documentElement || element === doc.body);
}
/**
* Scroll Module. This class contains 4 simple static functions
* to be used to access Element.scrollTop/scrollLeft properties.
* To solve the inconsistencies between browsers when either
* document.body or document.documentElement is supplied,
* below logic will be used to alleviate the issue:
*
* 1. If 'element' is either 'document.body' or 'document.documentElement,
* get whichever element's 'scroll{Top,Left}' is larger.
* 2. If 'element' is either 'document.body' or 'document.documentElement',
* set the 'scroll{Top,Left}' on both elements.
*/
var Scroll = {
/**
* @param {DOMElement} element
* @return {number}
*/
getTop: function getTop(element) {
var doc = element.ownerDocument;
return _isViewportScrollElement(element, doc) ?
// In practice, they will either both have the same value,
// or one will be zero and the other will be the scroll position
// of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
},
/**
* @param {DOMElement} element
* @param {number} newTop
*/
setTop: function setTop(element, newTop) {
var doc = element.ownerDocument;
if (_isViewportScrollElement(element, doc)) {
doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
} else {
element.scrollTop = newTop;
}
},
/**
* @param {DOMElement} element
* @return {number}
*/
getLeft: function getLeft(element) {
var doc = element.ownerDocument;
return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
},
/**
* @param {DOMElement} element
* @param {number} newLeft
*/
setLeft: function setLeft(element, newLeft) {
var doc = element.ownerDocument;
if (_isViewportScrollElement(element, doc)) {
doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
} else {
element.scrollLeft = newLeft;
}
}
};
module.exports = Scroll;

View File

@@ -0,0 +1,82 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule Scroll
*/
/**
* @param {DOMElement} element
* @param {DOMDocument} doc
* @return {boolean}
*/
function _isViewportScrollElement(element, doc) {
return !!doc && (element === doc.documentElement || element === doc.body);
}
/**
* Scroll Module. This class contains 4 simple static functions
* to be used to access Element.scrollTop/scrollLeft properties.
* To solve the inconsistencies between browsers when either
* document.body or document.documentElement is supplied,
* below logic will be used to alleviate the issue:
*
* 1. If 'element' is either 'document.body' or 'document.documentElement,
* get whichever element's 'scroll{Top,Left}' is larger.
* 2. If 'element' is either 'document.body' or 'document.documentElement',
* set the 'scroll{Top,Left}' on both elements.
*/
const Scroll = {
/**
* @param {DOMElement} element
* @return {number}
*/
getTop: function (element) {
const doc = element.ownerDocument;
return _isViewportScrollElement(element, doc) ?
// In practice, they will either both have the same value,
// or one will be zero and the other will be the scroll position
// of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
},
/**
* @param {DOMElement} element
* @param {number} newTop
*/
setTop: function (element, newTop) {
const doc = element.ownerDocument;
if (_isViewportScrollElement(element, doc)) {
doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
} else {
element.scrollTop = newTop;
}
},
/**
* @param {DOMElement} element
* @return {number}
*/
getLeft: function (element) {
const doc = element.ownerDocument;
return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
},
/**
* @param {DOMElement} element
* @param {number} newLeft
*/
setLeft: function (element, newLeft) {
const doc = element.ownerDocument;
if (_isViewportScrollElement(element, doc)) {
doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
} else {
element.scrollLeft = newLeft;
}
}
};
module.exports = Scroll;

View File

@@ -0,0 +1,11 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
module.exports = require('core-js/library/es6/set');

View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule Set
*/
module.exports = require('core-js/library/es6/set');

View File

@@ -0,0 +1,62 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
var getStyleProperty = require('./getStyleProperty');
/**
* @param {DOMNode} element [description]
* @param {string} name Overflow style property name.
* @return {boolean} True if the supplied ndoe is scrollable.
*/
function _isNodeScrollable(element, name) {
var overflow = Style.get(element, name);
return overflow === 'auto' || overflow === 'scroll';
}
/**
* Utilities for querying and mutating style properties.
*/
var Style = {
/**
* Gets the style property for the supplied node. This will return either the
* computed style, if available, or the declared style.
*
* @param {DOMNode} node
* @param {string} name Style property name.
* @return {?string} Style property value.
*/
get: getStyleProperty,
/**
* Determines the nearest ancestor of a node that is scrollable.
*
* NOTE: This can be expensive if used repeatedly or on a node nested deeply.
*
* @param {?DOMNode} node Node from which to start searching.
* @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
*/
getScrollParent: function getScrollParent(node) {
if (!node) {
return null;
}
var ownerDocument = node.ownerDocument;
while (node && node !== ownerDocument.body) {
if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
return node;
}
node = node.parentNode;
}
return ownerDocument.defaultView || ownerDocument.parentWindow;
}
};
module.exports = Style;

View File

@@ -0,0 +1,61 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule Style
* @typechecks
*/
var getStyleProperty = require('./getStyleProperty');
/**
* @param {DOMNode} element [description]
* @param {string} name Overflow style property name.
* @return {boolean} True if the supplied ndoe is scrollable.
*/
function _isNodeScrollable(element, name) {
var overflow = Style.get(element, name);
return overflow === 'auto' || overflow === 'scroll';
}
/**
* Utilities for querying and mutating style properties.
*/
var Style = {
/**
* Gets the style property for the supplied node. This will return either the
* computed style, if available, or the declared style.
*
* @param {DOMNode} node
* @param {string} name Style property name.
* @return {?string} Style property value.
*/
get: getStyleProperty,
/**
* Determines the nearest ancestor of a node that is scrollable.
*
* NOTE: This can be expensive if used repeatedly or on a node nested deeply.
*
* @param {?DOMNode} node Node from which to start searching.
* @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
*/
getScrollParent: function (node) {
if (!node) {
return null;
}
var ownerDocument = node.ownerDocument;
while (node && node !== ownerDocument.body) {
if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
return node;
}
node = node.parentNode;
}
return ownerDocument.defaultView || ownerDocument.parentWindow;
}
};
module.exports = Style;

View File

@@ -0,0 +1,35 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
* @stub
*
*/
'use strict';
// \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
// is latin supplement punctuation except fractions and superscript
// numbers
// \u2010-\u2027\u2030-\u205e
// is punctuation from the general punctuation block:
// weird quotes, commas, bullets, dashes, etc.
// \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
// is CJK punctuation
// \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
// is some full-width/half-width punctuation
// \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
// is some Arabic punctuation marks
// \u1801\u0964\u104a\u104b
// is misc. other language punctuation marks
var PUNCTUATION = '[.,+*?$|#{}()\'\\^\\-\\[\\]\\\\\\/!@%"~=<>_:;' + '\u30FB\u3001\u3002\u3008-\u3011\u3014-\u301F\uFF1A-\uFF1F\uFF01-\uFF0F' + '\uFF3B-\uFF40\uFF5B-\uFF65\u2E2E\u061F\u066A-\u066C\u061B\u060C\u060D' + '\uFD3E\uFD3F\u1801\u0964\u104A\u104B\u2010-\u2027\u2030-\u205E' + '\xA1-\xB1\xB4-\xB8\xBA\xBB\xBF]';
module.exports = {
getPunctuation: function getPunctuation() {
return PUNCTUATION;
}
};

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule TokenizeUtil
* @typechecks
* @stub
* @flow
*/
'use strict';
// \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
// is latin supplement punctuation except fractions and superscript
// numbers
// \u2010-\u2027\u2030-\u205e
// is punctuation from the general punctuation block:
// weird quotes, commas, bullets, dashes, etc.
// \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
// is CJK punctuation
// \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
// is some full-width/half-width punctuation
// \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
// is some Arabic punctuation marks
// \u1801\u0964\u104a\u104b
// is misc. other language punctuation marks
var PUNCTUATION = '[.,+*?$|#{}()\'\\^\\-\\[\\]\\\\\\/!@%"~=<>_:;' + '\u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f\uff1a-\uff1f\uff01-\uff0f' + '\uff3b-\uff40\uff5b-\uff65\u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d' + '\uFD3e\uFD3F\u1801\u0964\u104a\u104b\u2010-\u2027\u2030-\u205e' + '\u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf]';
module.exports = {
getPunctuation: (): string => PUNCTUATION
};

View File

@@ -0,0 +1,32 @@
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
var TouchEventUtils = {
/**
* Utility function for common case of extracting out the primary touch from a
* touch event.
* - `touchEnd` events usually do not have the `touches` property.
* http://stackoverflow.com/questions/3666929/
* mobile-sarai-touchend-event-not-firing-when-last-touch-is-removed
*
* @param {Event} nativeEvent Native event that may or may not be a touch.
* @return {TouchesObject?} an object with pageX and pageY or null.
*/
extractSingleTouch: function extractSingleTouch(nativeEvent) {
var touches = nativeEvent.touches;
var changedTouches = nativeEvent.changedTouches;
var hasTouches = touches && touches.length > 0;
var hasChangedTouches = changedTouches && changedTouches.length > 0;
return !hasTouches && hasChangedTouches ? changedTouches[0] : hasTouches ? touches[0] : nativeEvent;
}
};
module.exports = TouchEventUtils;

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule TouchEventUtils
*/
const TouchEventUtils = {
/**
* Utility function for common case of extracting out the primary touch from a
* touch event.
* - `touchEnd` events usually do not have the `touches` property.
* http://stackoverflow.com/questions/3666929/
* mobile-sarai-touchend-event-not-firing-when-last-touch-is-removed
*
* @param {Event} nativeEvent Native event that may or may not be a touch.
* @return {TouchesObject?} an object with pageX and pageY or null.
*/
extractSingleTouch: function (nativeEvent) {
const touches = nativeEvent.touches;
const changedTouches = nativeEvent.changedTouches;
const hasTouches = touches && touches.length > 0;
const hasChangedTouches = changedTouches && changedTouches.length > 0;
return !hasTouches && hasChangedTouches ? changedTouches[0] : hasTouches ? touches[0] : nativeEvent;
}
};
module.exports = TouchEventUtils;

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var URI = function () {
function URI(uri) {
_classCallCheck(this, URI);
this._uri = uri;
}
URI.prototype.toString = function toString() {
return this._uri;
};
return URI;
}();
module.exports = URI;

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule URI
* @flow
*/
'use strict';
class URI {
_uri: string;
constructor(uri: string) {
this._uri = uri;
}
toString(): string {
return this._uri;
}
}
module.exports = URI;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,106 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*
*/
/**
* Constants to represent text directionality
*
* Also defines a *global* direciton, to be used in bidi algorithms as a
* default fallback direciton, when no better direction is found or provided.
*
* NOTE: Use `setGlobalDir()`, or update `initGlobalDir()`, to set the initial
* global direction value based on the application.
*
* Part of the implementation of Unicode Bidirectional Algorithm (UBA)
* Unicode Standard Annex #9 (UAX9)
* http://www.unicode.org/reports/tr9/
*/
'use strict';
var invariant = require('./invariant');
var NEUTRAL = 'NEUTRAL'; // No strong direction
var LTR = 'LTR'; // Left-to-Right direction
var RTL = 'RTL'; // Right-to-Left direction
var globalDir = null;
// == Helpers ==
/**
* Check if a directionality value is a Strong one
*/
function isStrong(dir) {
return dir === LTR || dir === RTL;
}
/**
* Get string value to be used for `dir` HTML attribute or `direction` CSS
* property.
*/
function getHTMLDir(dir) {
!isStrong(dir) ? process.env.NODE_ENV !== 'production' ? invariant(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant(false) : void 0;
return dir === LTR ? 'ltr' : 'rtl';
}
/**
* Get string value to be used for `dir` HTML attribute or `direction` CSS
* property, but returns null if `dir` has same value as `otherDir`.
* `null`.
*/
function getHTMLDirIfDifferent(dir, otherDir) {
!isStrong(dir) ? process.env.NODE_ENV !== 'production' ? invariant(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant(false) : void 0;
!isStrong(otherDir) ? process.env.NODE_ENV !== 'production' ? invariant(false, '`otherDir` must be a strong direction to be converted to HTML Direction') : invariant(false) : void 0;
return dir === otherDir ? null : getHTMLDir(dir);
}
// == Global Direction ==
/**
* Set the global direction.
*/
function setGlobalDir(dir) {
globalDir = dir;
}
/**
* Initialize the global direction
*/
function initGlobalDir() {
setGlobalDir(LTR);
}
/**
* Get the global direction
*/
function getGlobalDir() {
if (!globalDir) {
this.initGlobalDir();
}
!globalDir ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Global direction not set.') : invariant(false) : void 0;
return globalDir;
}
var UnicodeBidiDirection = {
// Values
NEUTRAL: NEUTRAL,
LTR: LTR,
RTL: RTL,
// Helpers
isStrong: isStrong,
getHTMLDir: getHTMLDir,
getHTMLDirIfDifferent: getHTMLDirIfDifferent,
// Global Direction
setGlobalDir: setGlobalDir,
initGlobalDir: initGlobalDir,
getGlobalDir: getGlobalDir
};
module.exports = UnicodeBidiDirection;

View File

@@ -0,0 +1,110 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule UnicodeBidiDirection
* @typechecks
* @flow
*/
/**
* Constants to represent text directionality
*
* Also defines a *global* direciton, to be used in bidi algorithms as a
* default fallback direciton, when no better direction is found or provided.
*
* NOTE: Use `setGlobalDir()`, or update `initGlobalDir()`, to set the initial
* global direction value based on the application.
*
* Part of the implementation of Unicode Bidirectional Algorithm (UBA)
* Unicode Standard Annex #9 (UAX9)
* http://www.unicode.org/reports/tr9/
*/
'use strict';
const invariant = require('./invariant');
export type BidiDirection = 'LTR' | 'RTL' | 'NEUTRAL';
export type HTMLDir = 'ltr' | 'rtl';
const NEUTRAL = 'NEUTRAL'; // No strong direction
const LTR = 'LTR'; // Left-to-Right direction
const RTL = 'RTL'; // Right-to-Left direction
let globalDir: ?BidiDirection = null;
// == Helpers ==
/**
* Check if a directionality value is a Strong one
*/
function isStrong(dir: BidiDirection): boolean {
return dir === LTR || dir === RTL;
}
/**
* Get string value to be used for `dir` HTML attribute or `direction` CSS
* property.
*/
function getHTMLDir(dir: BidiDirection): HTMLDir {
invariant(isStrong(dir), '`dir` must be a strong direction to be converted to HTML Direction');
return dir === LTR ? 'ltr' : 'rtl';
}
/**
* Get string value to be used for `dir` HTML attribute or `direction` CSS
* property, but returns null if `dir` has same value as `otherDir`.
* `null`.
*/
function getHTMLDirIfDifferent(dir: BidiDirection, otherDir: BidiDirection): ?HTMLDir {
invariant(isStrong(dir), '`dir` must be a strong direction to be converted to HTML Direction');
invariant(isStrong(otherDir), '`otherDir` must be a strong direction to be converted to HTML Direction');
return dir === otherDir ? null : getHTMLDir(dir);
}
// == Global Direction ==
/**
* Set the global direction.
*/
function setGlobalDir(dir: BidiDirection): void {
globalDir = dir;
}
/**
* Initialize the global direction
*/
function initGlobalDir(): void {
setGlobalDir(LTR);
}
/**
* Get the global direction
*/
function getGlobalDir(): BidiDirection {
if (!globalDir) {
this.initGlobalDir();
}
invariant(globalDir, 'Global direction not set.');
return globalDir;
}
const UnicodeBidiDirection = {
// Values
NEUTRAL,
LTR,
RTL,
// Helpers
isStrong,
getHTMLDir,
getHTMLDirIfDifferent,
// Global Direction
setGlobalDir,
initGlobalDir,
getGlobalDir
};
module.exports = UnicodeBidiDirection;

View File

@@ -0,0 +1,98 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*
*/
/**
* Stateful API for text direction detection
*
* This class can be used in applications where you need to detect the
* direction of a sequence of text blocks, where each direction shall be used
* as the fallback direction for the next one.
*
* NOTE: A default direction, if not provided, is set based on the global
* direction, as defined by `UnicodeBidiDirection`.
*
* == Example ==
* ```
* var UnicodeBidiService = require('UnicodeBidiService');
*
* var bidiService = new UnicodeBidiService();
*
* ...
*
* bidiService.reset();
* for (var para in paragraphs) {
* var dir = bidiService.getDirection(para);
* ...
* }
* ```
*
* Part of our implementation of Unicode Bidirectional Algorithm (UBA)
* Unicode Standard Annex #9 (UAX9)
* http://www.unicode.org/reports/tr9/
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var UnicodeBidi = require('./UnicodeBidi');
var UnicodeBidiDirection = require('./UnicodeBidiDirection');
var invariant = require('./invariant');
var UnicodeBidiService = function () {
/**
* Stateful class for paragraph direction detection
*
* @param defaultDir Default direction of the service
*/
function UnicodeBidiService(defaultDir) {
_classCallCheck(this, UnicodeBidiService);
if (!defaultDir) {
defaultDir = UnicodeBidiDirection.getGlobalDir();
} else {
!UnicodeBidiDirection.isStrong(defaultDir) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Default direction must be a strong direction (LTR or RTL)') : invariant(false) : void 0;
}
this._defaultDir = defaultDir;
this.reset();
}
/**
* Reset the internal state
*
* Instead of creating a new instance, you can just reset() your instance
* everytime you start a new loop.
*/
UnicodeBidiService.prototype.reset = function reset() {
this._lastDir = this._defaultDir;
};
/**
* Returns the direction of a block of text, and remembers it as the
* fall-back direction for the next paragraph.
*
* @param str A text block, e.g. paragraph, table cell, tag
* @return The resolved direction
*/
UnicodeBidiService.prototype.getDirection = function getDirection(str) {
this._lastDir = UnicodeBidi.getDirection(str, this._lastDir);
return this._lastDir;
};
return UnicodeBidiService;
}();
module.exports = UnicodeBidiService;

View File

@@ -0,0 +1,95 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule UnicodeBidiService
* @typechecks
* @flow
*/
/**
* Stateful API for text direction detection
*
* This class can be used in applications where you need to detect the
* direction of a sequence of text blocks, where each direction shall be used
* as the fallback direction for the next one.
*
* NOTE: A default direction, if not provided, is set based on the global
* direction, as defined by `UnicodeBidiDirection`.
*
* == Example ==
* ```
* var UnicodeBidiService = require('UnicodeBidiService');
*
* var bidiService = new UnicodeBidiService();
*
* ...
*
* bidiService.reset();
* for (var para in paragraphs) {
* var dir = bidiService.getDirection(para);
* ...
* }
* ```
*
* Part of our implementation of Unicode Bidirectional Algorithm (UBA)
* Unicode Standard Annex #9 (UAX9)
* http://www.unicode.org/reports/tr9/
*/
'use strict';
const UnicodeBidi = require('./UnicodeBidi');
const UnicodeBidiDirection = require('./UnicodeBidiDirection');
const invariant = require('./invariant');
import type { BidiDirection } from './UnicodeBidiDirection';
class UnicodeBidiService {
_defaultDir: BidiDirection;
_lastDir: BidiDirection;
/**
* Stateful class for paragraph direction detection
*
* @param defaultDir Default direction of the service
*/
constructor(defaultDir: ?BidiDirection) {
if (!defaultDir) {
defaultDir = UnicodeBidiDirection.getGlobalDir();
} else {
invariant(UnicodeBidiDirection.isStrong(defaultDir), 'Default direction must be a strong direction (LTR or RTL)');
}
this._defaultDir = defaultDir;
this.reset();
}
/**
* Reset the internal state
*
* Instead of creating a new instance, you can just reset() your instance
* everytime you start a new loop.
*/
reset(): void {
this._lastDir = this._defaultDir;
}
/**
* Returns the direction of a block of text, and remembers it as the
* fall-back direction for the next paragraph.
*
* @param str A text block, e.g. paragraph, table cell, tag
* @return The resolved direction
*/
getDirection(str: string): BidiDirection {
this._lastDir = UnicodeBidi.getDirection(str, this._lastDir);
return this._lastDir;
}
}
module.exports = UnicodeBidiService;

View File

@@ -0,0 +1,172 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
/**
* Unicode algorithms for CJK (Chinese, Japanese, Korean) writing systems.
*
* Utilities for Hanzi/Kanji/Hanja logographs and Kanas (Katakana and Hiragana)
* syllables.
*
* For Korean Hangul see module `UnicodeHangulKorean`.
*/
'use strict';
/**
* Latin
*
* NOTE: The code assumes these sets include only BMP characters.
*/
var R_LATIN_ASCII = 'a-zA-Z';
var R_LATIN_FULLWIDTH = '\uFF21-\uFF3A\uFF41-\uFF5A';
var R_LATIN = R_LATIN_ASCII + R_LATIN_FULLWIDTH;
/**
* Hiragana & Katakana
*
* NOTE: Some ranges include non-BMP characters. We do not support those ranges
* for now.
*/
var R_HIRAGANA = '\u3040-\u309F';
var R_KATAKANA = '\u30A0-\u30FF';
var R_KATAKANA_PHONETIC = '\u31F0-\u31FF';
var R_KATAKANA_HALFWIDTH = '\uFF65-\uFF9F';
// var R_KANA_SUPPLEMENT = '\U0001B000-\U0001B0FF';
var R_KATAKANA_ALL = R_KATAKANA + R_KATAKANA_PHONETIC + R_KATAKANA_HALFWIDTH;
var R_KANA = R_HIRAGANA + R_KATAKANA_ALL;
var I_HIRAGANA = [0x3040, 0x309F];
var I_KATAKANA = [0x30A0, 0x30FF];
var I_HIRAGANA_TO_KATAKANA = I_KATAKANA[0] - I_HIRAGANA[0];
/**
* Hanzi/Kanji/Hanja
*
* NOTE: Some ranges include non-BMP characters. We do not support those ranges
* for now.
*/
var R_IDEO_MAIN = '\u4E00-\u9FCF';
var R_IDEO_EXT_A = '\u3400-\u4DBF';
// var R_IDEO_EXT_B = '\U00020000-\U0002A6DF';
// var R_IDEO_EXT_C = '\U0002A700-\U0002B73F';
// var R_IDEO_EXT_D = '\U0002B740-\U0002B81F';
var R_IDEO = R_IDEO_MAIN + R_IDEO_EXT_A;
/**
* Hangul
*/
// var R_HANGUL_JAMO = '\u1100-\u11FF';
// var R_HANGUL_JAMO_EXT_A = '\uA960-\uA97F';
// var R_HANGUL_JAMO_EXT_B = '\uD7B0-\uD7FF';
// var R_HANGUL_COMPATIBILITY = '\u3130-\u318F';
// var R_HANGUL_COMP_HALFWIDTH = '\uFFA0-\uFFDF';
var R_HANGUL_SYLLABLES = '\uAC00-\uD7AF';
/**
* Globals
*/
var R_IDEO_OR_SYLL = R_IDEO + R_KANA + R_HANGUL_SYLLABLES;
var REGEX_IDEO = null;
var REGEX_KANA = null;
var REGEX_IDEO_OR_SYLL = null;
var REGEX_IS_KANA_WITH_TRAILING_LATIN = null;
/**
* Whether the string includes any Katakana or Hiragana characters.
*
* @param {string} str
* @return {boolean}
*/
function hasKana(str) {
REGEX_KANA = REGEX_KANA || new RegExp('[' + R_KANA + ']');
return REGEX_KANA.test(str);
}
/**
* Whether the string includes any CJK Ideograph characters.
*
* @param {string} str
* @return {boolean}
*/
function hasIdeograph(str) {
REGEX_IDEO = REGEX_IDEO || new RegExp('[' + R_IDEO + ']');
return REGEX_IDEO.test(str);
}
/**
* Whether the string includes any CJK Ideograph or Syllable characters.
*
* @param {string} str
* @return {boolean}
*/
function hasIdeoOrSyll(str) {
REGEX_IDEO_OR_SYLL = REGEX_IDEO_OR_SYLL || new RegExp('[' + R_IDEO_OR_SYLL + ']');
return REGEX_IDEO_OR_SYLL.test(str);
}
/**
* @param {string} chr
* @output {string}
*/
function charCodeToKatakana(chr) {
var charCode = chr.charCodeAt(0);
return String.fromCharCode(charCode < I_HIRAGANA[0] || charCode > I_HIRAGANA[1] ? charCode : charCode + I_HIRAGANA_TO_KATAKANA);
}
/**
* Replace any Hiragana character with the matching Katakana
*
* @param {string} str
* @output {string}
*/
function hiraganaToKatakana(str) {
if (!hasKana(str)) {
return str;
}
return str.split('').map(charCodeToKatakana).join('');
}
/**
* Whether the string is exactly a sequence of Kana characters followed by one
* Latin character.
*
* @param {string} str
* @output {string}
*/
function isKanaWithTrailingLatin(str) {
REGEX_IS_KANA_WITH_TRAILING_LATIN = REGEX_IS_KANA_WITH_TRAILING_LATIN || new RegExp('^' + '[' + R_KANA + ']+' + '[' + R_LATIN + ']' + '$');
return REGEX_IS_KANA_WITH_TRAILING_LATIN.test(str);
}
/**
* Drops the trailing Latin character from a string that is exactly a sequence
* of Kana characters followed by one Latin character.
*
* @param {string} str
* @output {string}
*/
function kanaRemoveTrailingLatin(str) {
if (isKanaWithTrailingLatin(str)) {
return str.substr(0, str.length - 1);
}
return str;
}
var UnicodeCJK = {
hasKana: hasKana,
hasIdeograph: hasIdeograph,
hasIdeoOrSyll: hasIdeoOrSyll,
hiraganaToKatakana: hiraganaToKatakana,
isKanaWithTrailingLatin: isKanaWithTrailingLatin,
kanaRemoveTrailingLatin: kanaRemoveTrailingLatin
};
module.exports = UnicodeCJK;

View File

@@ -0,0 +1,173 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule UnicodeCJK
* @typechecks
*/
/**
* Unicode algorithms for CJK (Chinese, Japanese, Korean) writing systems.
*
* Utilities for Hanzi/Kanji/Hanja logographs and Kanas (Katakana and Hiragana)
* syllables.
*
* For Korean Hangul see module `UnicodeHangulKorean`.
*/
'use strict';
/**
* Latin
*
* NOTE: The code assumes these sets include only BMP characters.
*/
const R_LATIN_ASCII = 'a-zA-Z';
const R_LATIN_FULLWIDTH = '\uFF21-\uFF3A\uFF41-\uFF5A';
const R_LATIN = R_LATIN_ASCII + R_LATIN_FULLWIDTH;
/**
* Hiragana & Katakana
*
* NOTE: Some ranges include non-BMP characters. We do not support those ranges
* for now.
*/
const R_HIRAGANA = '\u3040-\u309F';
const R_KATAKANA = '\u30A0-\u30FF';
const R_KATAKANA_PHONETIC = '\u31F0-\u31FF';
const R_KATAKANA_HALFWIDTH = '\uFF65-\uFF9F';
// var R_KANA_SUPPLEMENT = '\U0001B000-\U0001B0FF';
const R_KATAKANA_ALL = R_KATAKANA + R_KATAKANA_PHONETIC + R_KATAKANA_HALFWIDTH;
const R_KANA = R_HIRAGANA + R_KATAKANA_ALL;
const I_HIRAGANA = [0x3040, 0x309F];
const I_KATAKANA = [0x30A0, 0x30FF];
const I_HIRAGANA_TO_KATAKANA = I_KATAKANA[0] - I_HIRAGANA[0];
/**
* Hanzi/Kanji/Hanja
*
* NOTE: Some ranges include non-BMP characters. We do not support those ranges
* for now.
*/
const R_IDEO_MAIN = '\u4E00-\u9FCF';
const R_IDEO_EXT_A = '\u3400-\u4DBF';
// var R_IDEO_EXT_B = '\U00020000-\U0002A6DF';
// var R_IDEO_EXT_C = '\U0002A700-\U0002B73F';
// var R_IDEO_EXT_D = '\U0002B740-\U0002B81F';
const R_IDEO = R_IDEO_MAIN + R_IDEO_EXT_A;
/**
* Hangul
*/
// var R_HANGUL_JAMO = '\u1100-\u11FF';
// var R_HANGUL_JAMO_EXT_A = '\uA960-\uA97F';
// var R_HANGUL_JAMO_EXT_B = '\uD7B0-\uD7FF';
// var R_HANGUL_COMPATIBILITY = '\u3130-\u318F';
// var R_HANGUL_COMP_HALFWIDTH = '\uFFA0-\uFFDF';
const R_HANGUL_SYLLABLES = '\uAC00-\uD7AF';
/**
* Globals
*/
const R_IDEO_OR_SYLL = R_IDEO + R_KANA + R_HANGUL_SYLLABLES;
let REGEX_IDEO = null;
let REGEX_KANA = null;
let REGEX_IDEO_OR_SYLL = null;
let REGEX_IS_KANA_WITH_TRAILING_LATIN = null;
/**
* Whether the string includes any Katakana or Hiragana characters.
*
* @param {string} str
* @return {boolean}
*/
function hasKana(str) {
REGEX_KANA = REGEX_KANA || new RegExp('[' + R_KANA + ']');
return REGEX_KANA.test(str);
}
/**
* Whether the string includes any CJK Ideograph characters.
*
* @param {string} str
* @return {boolean}
*/
function hasIdeograph(str) {
REGEX_IDEO = REGEX_IDEO || new RegExp('[' + R_IDEO + ']');
return REGEX_IDEO.test(str);
}
/**
* Whether the string includes any CJK Ideograph or Syllable characters.
*
* @param {string} str
* @return {boolean}
*/
function hasIdeoOrSyll(str) {
REGEX_IDEO_OR_SYLL = REGEX_IDEO_OR_SYLL || new RegExp('[' + R_IDEO_OR_SYLL + ']');
return REGEX_IDEO_OR_SYLL.test(str);
}
/**
* @param {string} chr
* @output {string}
*/
function charCodeToKatakana(chr) {
const charCode = chr.charCodeAt(0);
return String.fromCharCode(charCode < I_HIRAGANA[0] || charCode > I_HIRAGANA[1] ? charCode : charCode + I_HIRAGANA_TO_KATAKANA);
}
/**
* Replace any Hiragana character with the matching Katakana
*
* @param {string} str
* @output {string}
*/
function hiraganaToKatakana(str) {
if (!hasKana(str)) {
return str;
}
return str.split('').map(charCodeToKatakana).join('');
}
/**
* Whether the string is exactly a sequence of Kana characters followed by one
* Latin character.
*
* @param {string} str
* @output {string}
*/
function isKanaWithTrailingLatin(str) {
REGEX_IS_KANA_WITH_TRAILING_LATIN = REGEX_IS_KANA_WITH_TRAILING_LATIN || new RegExp('^' + '[' + R_KANA + ']+' + '[' + R_LATIN + ']' + '$');
return REGEX_IS_KANA_WITH_TRAILING_LATIN.test(str);
}
/**
* Drops the trailing Latin character from a string that is exactly a sequence
* of Kana characters followed by one Latin character.
*
* @param {string} str
* @output {string}
*/
function kanaRemoveTrailingLatin(str) {
if (isKanaWithTrailingLatin(str)) {
return str.substr(0, str.length - 1);
}
return str;
}
const UnicodeCJK = {
hasKana: hasKana,
hasIdeograph: hasIdeograph,
hasIdeoOrSyll: hasIdeoOrSyll,
hiraganaToKatakana: hiraganaToKatakana,
isKanaWithTrailingLatin: isKanaWithTrailingLatin,
kanaRemoveTrailingLatin: kanaRemoveTrailingLatin
};
module.exports = UnicodeCJK;

View File

@@ -0,0 +1,135 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
/**
* Unicode algorithms for Hangul script, the Korean writing system
*
* Hangul script has three encoded models in Unicode:
*
* A) Conjoining Jamo (covers modern and historic elements)
* * U+1100..U+11FF ; Hangul Jamo
* * U+A960..U+A97F ; Hangul Jamo Extended-A
* * U+D7B0..U+D7FF ; Hangul Jamo Extended-B
*
* B) Conjoined Syllables (only covers modern Korean language)
* * U+AC00..U+D7AF ; Hangul Syllables
*
* C) Compatibility Jamo (one code-point for each "shape")
* * U+3130..U+318F ; Hangul Compatibility Jamo
*
* This modules helps you convert characters from one model to another.
* Primary functionalities are:
*
* 1) Convert from any encodings to Conjoining Jamo characters (A),
* e.g. for prefix matching
*
* 2) Convert from any encodings to Syllable characters, when possible (B),
* e.g. to reach the normal Unicode form (NFC)
*/
'use strict';
var HANGUL_COMPATIBILITY_OR_SYLLABLE_REGEX = /[\u3130-\u318F\uAC00-\uD7AF]/;
/**
* Returns true if the input includes any Hangul Compatibility Jamo or
* Hangul Conjoined Syllable.
*
* @param {string} str
*/
function hasCompatibilityOrSyllable(str) {
return HANGUL_COMPATIBILITY_OR_SYLLABLE_REGEX.test(str);
}
/* Compatibility Jamo -> Conjoining Jamo
*
* Maps a compatibility character to the Conjoining Jamo character,
* positioned at (compatibilityCodePoint - 0x3131).
*
* Generated by:
* $ grep '^31[3-8].;' UnicodeData.txt |\
* awk -F';' '{print $6}' | awk '{print " 0x"$2","}'
*/
var CMAP = [0x1100, 0x1101, 0x11AA, 0x1102, 0x11AC, 0x11AD, 0x1103, 0x1104, 0x1105, 0x11B0, 0x11B1, 0x11B2, 0x11B3, 0x11B4, 0x11B5, 0x111A, 0x1106, 0x1107, 0x1108, 0x1121, 0x1109, 0x110A, 0x110B, 0x110C, 0x110D, 0x110E, 0x110F, 0x1110, 0x1111, 0x1112, 0x1161, 0x1162, 0x1163, 0x1164, 0x1165, 0x1166, 0x1167, 0x1168, 0x1169, 0x116A, 0x116B, 0x116C, 0x116D, 0x116E, 0x116F, 0x1170, 0x1171, 0x1172, 0x1173, 0x1174, 0x1175, 0x1160, 0x1114, 0x1115, 0x11C7, 0x11C8, 0x11CC, 0x11CE, 0x11D3, 0x11D7, 0x11D9, 0x111C, 0x11DD, 0x11DF, 0x111D, 0x111E, 0x1120, 0x1122, 0x1123, 0x1127, 0x1129, 0x112B, 0x112C, 0x112D, 0x112E, 0x112F, 0x1132, 0x1136, 0x1140, 0x1147, 0x114C, 0x11F1, 0x11F2, 0x1157, 0x1158, 0x1159, 0x1184, 0x1185, 0x1188, 0x1191, 0x1192, 0x1194, 0x119E, 0x11A1];
var CBASE = 0x3131;
var CCOUNT = CMAP.length;
var CTOP = CBASE + CCOUNT;
/**
* Maps one Hangul Compatibility Jamo code-point to the equivalent Hangul
* Conjoining Jamo characters, as defined in UnicodeData.txt.
*
* @param {number} codePoint One Unicode code-point
* @output {string}
*/
function fromCompatibility(codePoint) {
return String.fromCharCode(CMAP[codePoint - CBASE]);
}
/**
* Conjoined Syllable -> Conjoining Jamo
*
* Based on the "Hangul Syllable Decomposition" algorithm provided in
* 3.12 Conjoining Jamo Behavior, The Unicode Standard, Version 6.3.0.
* <http://www.unicode.org/versions/Unicode6.2.0/ch03.pdf>
*/
var LBASE = 0x1100;
var VBASE = 0x1161;
var TBASE = 0x11A7;
var SBASE = 0xAC00;
var LCOUNT = 19;
var VCOUNT = 21;
var TCOUNT = 28;
var NCOUNT = VCOUNT * TCOUNT;
var SCOUNT = LCOUNT * NCOUNT;
var STOP = SBASE + SCOUNT;
/**
* Maps one Hangul Syllable code-point to the equivalent Hangul
* Conjoining Jamo characters, as defined in UnicodeData.txt.
*
* @param {number} codePoint One Unicode character
* @output {string}
*/
function decomposeSyllable(codePoint) {
var sylSIndex = codePoint - SBASE;
var sylTIndex = sylSIndex % TCOUNT;
return String.fromCharCode(LBASE + sylSIndex / NCOUNT) + String.fromCharCode(VBASE + sylSIndex % NCOUNT / TCOUNT) + (sylTIndex > 0 ? String.fromCharCode(TBASE + sylTIndex) : '');
}
/* To Conjoining Jamo */
/**
* Return Unicode characters as they are, except for Hangul characters, which
* will be converted to the Conjoining Jamo form.
*
* @param {string} string
* @output {string}
*/
function toConjoiningJamo(string) {
if (!hasCompatibilityOrSyllable(string)) {
return string;
}
var result = [];
for (var i = 0; i < string.length; i++) {
var charStr = string.charAt(i);
var codeUnit = charStr.charCodeAt(0);
result.push(CBASE <= codeUnit && codeUnit < CTOP ? fromCompatibility(codeUnit) : SBASE <= codeUnit && codeUnit < STOP ? decomposeSyllable(codeUnit) : charStr);
}
return result.join('');
}
var UnicodeHangulKorean = {
toConjoiningJamo: toConjoiningJamo
};
module.exports = UnicodeHangulKorean;

View File

@@ -0,0 +1,136 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule UnicodeHangulKorean
* @typechecks
*/
/**
* Unicode algorithms for Hangul script, the Korean writing system
*
* Hangul script has three encoded models in Unicode:
*
* A) Conjoining Jamo (covers modern and historic elements)
* * U+1100..U+11FF ; Hangul Jamo
* * U+A960..U+A97F ; Hangul Jamo Extended-A
* * U+D7B0..U+D7FF ; Hangul Jamo Extended-B
*
* B) Conjoined Syllables (only covers modern Korean language)
* * U+AC00..U+D7AF ; Hangul Syllables
*
* C) Compatibility Jamo (one code-point for each "shape")
* * U+3130..U+318F ; Hangul Compatibility Jamo
*
* This modules helps you convert characters from one model to another.
* Primary functionalities are:
*
* 1) Convert from any encodings to Conjoining Jamo characters (A),
* e.g. for prefix matching
*
* 2) Convert from any encodings to Syllable characters, when possible (B),
* e.g. to reach the normal Unicode form (NFC)
*/
'use strict';
const HANGUL_COMPATIBILITY_OR_SYLLABLE_REGEX = /[\u3130-\u318F\uAC00-\uD7AF]/;
/**
* Returns true if the input includes any Hangul Compatibility Jamo or
* Hangul Conjoined Syllable.
*
* @param {string} str
*/
function hasCompatibilityOrSyllable(str) {
return HANGUL_COMPATIBILITY_OR_SYLLABLE_REGEX.test(str);
}
/* Compatibility Jamo -> Conjoining Jamo
*
* Maps a compatibility character to the Conjoining Jamo character,
* positioned at (compatibilityCodePoint - 0x3131).
*
* Generated by:
* $ grep '^31[3-8].;' UnicodeData.txt |\
* awk -F';' '{print $6}' | awk '{print " 0x"$2","}'
*/
const CMAP = [0x1100, 0x1101, 0x11AA, 0x1102, 0x11AC, 0x11AD, 0x1103, 0x1104, 0x1105, 0x11B0, 0x11B1, 0x11B2, 0x11B3, 0x11B4, 0x11B5, 0x111A, 0x1106, 0x1107, 0x1108, 0x1121, 0x1109, 0x110A, 0x110B, 0x110C, 0x110D, 0x110E, 0x110F, 0x1110, 0x1111, 0x1112, 0x1161, 0x1162, 0x1163, 0x1164, 0x1165, 0x1166, 0x1167, 0x1168, 0x1169, 0x116A, 0x116B, 0x116C, 0x116D, 0x116E, 0x116F, 0x1170, 0x1171, 0x1172, 0x1173, 0x1174, 0x1175, 0x1160, 0x1114, 0x1115, 0x11C7, 0x11C8, 0x11CC, 0x11CE, 0x11D3, 0x11D7, 0x11D9, 0x111C, 0x11DD, 0x11DF, 0x111D, 0x111E, 0x1120, 0x1122, 0x1123, 0x1127, 0x1129, 0x112B, 0x112C, 0x112D, 0x112E, 0x112F, 0x1132, 0x1136, 0x1140, 0x1147, 0x114C, 0x11F1, 0x11F2, 0x1157, 0x1158, 0x1159, 0x1184, 0x1185, 0x1188, 0x1191, 0x1192, 0x1194, 0x119E, 0x11A1];
const CBASE = 0x3131;
const CCOUNT = CMAP.length;
const CTOP = CBASE + CCOUNT;
/**
* Maps one Hangul Compatibility Jamo code-point to the equivalent Hangul
* Conjoining Jamo characters, as defined in UnicodeData.txt.
*
* @param {number} codePoint One Unicode code-point
* @output {string}
*/
function fromCompatibility(codePoint) {
return String.fromCharCode(CMAP[codePoint - CBASE]);
}
/**
* Conjoined Syllable -> Conjoining Jamo
*
* Based on the "Hangul Syllable Decomposition" algorithm provided in
* 3.12 Conjoining Jamo Behavior, The Unicode Standard, Version 6.3.0.
* <http://www.unicode.org/versions/Unicode6.2.0/ch03.pdf>
*/
const LBASE = 0x1100;
const VBASE = 0x1161;
const TBASE = 0x11A7;
const SBASE = 0xAC00;
const LCOUNT = 19;
const VCOUNT = 21;
const TCOUNT = 28;
const NCOUNT = VCOUNT * TCOUNT;
const SCOUNT = LCOUNT * NCOUNT;
const STOP = SBASE + SCOUNT;
/**
* Maps one Hangul Syllable code-point to the equivalent Hangul
* Conjoining Jamo characters, as defined in UnicodeData.txt.
*
* @param {number} codePoint One Unicode character
* @output {string}
*/
function decomposeSyllable(codePoint) {
const sylSIndex = codePoint - SBASE;
const sylTIndex = sylSIndex % TCOUNT;
return String.fromCharCode(LBASE + sylSIndex / NCOUNT) + String.fromCharCode(VBASE + sylSIndex % NCOUNT / TCOUNT) + (sylTIndex > 0 ? String.fromCharCode(TBASE + sylTIndex) : '');
}
/* To Conjoining Jamo */
/**
* Return Unicode characters as they are, except for Hangul characters, which
* will be converted to the Conjoining Jamo form.
*
* @param {string} string
* @output {string}
*/
function toConjoiningJamo(string) {
if (!hasCompatibilityOrSyllable(string)) {
return string;
}
const result = [];
for (let i = 0; i < string.length; i++) {
const charStr = string.charAt(i);
const codeUnit = charStr.charCodeAt(0);
result.push(CBASE <= codeUnit && codeUnit < CTOP ? fromCompatibility(codeUnit) : SBASE <= codeUnit && codeUnit < STOP ? decomposeSyllable(codeUnit) : charStr);
}
return result.join('');
}
const UnicodeHangulKorean = {
toConjoiningJamo: toConjoiningJamo
};
module.exports = UnicodeHangulKorean;

View File

@@ -0,0 +1,212 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
/**
* Unicode-enabled replacesments for basic String functions.
*
* All the functions in this module assume that the input string is a valid
* UTF-16 encoding of a Unicode sequence. If it's not the case, the behavior
* will be undefined.
*
* WARNING: Since this module is typechecks-enforced, you may find new bugs
* when replacing normal String functions with ones provided here.
*/
'use strict';
var invariant = require('./invariant');
// These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
// surrogate code unit.
var SURROGATE_HIGH_START = 0xD800;
var SURROGATE_HIGH_END = 0xDBFF;
var SURROGATE_LOW_START = 0xDC00;
var SURROGATE_LOW_END = 0xDFFF;
var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
/**
* @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
* @return {boolean} Whether code-unit is in a surrogate (hi/low) range
*/
function isCodeUnitInSurrogateRange(codeUnit) {
return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
}
/**
* Returns whether the two characters starting at `index` form a surrogate pair.
* For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
* (s, 1) returns false.
*
* @param {string} str
* @param {number} index
* @return {boolean}
*/
function isSurrogatePair(str, index) {
!(0 <= index && index < str.length) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'isSurrogatePair: Invalid index %s for string length %s.', index, str.length) : invariant(false) : void 0;
if (index + 1 === str.length) {
return false;
}
var first = str.charCodeAt(index);
var second = str.charCodeAt(index + 1);
return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
}
/**
* @param {string} str Non-empty string
* @return {boolean} True if the input includes any surrogate code units
*/
function hasSurrogateUnit(str) {
return SURROGATE_UNITS_REGEX.test(str);
}
/**
* Return the length of the original Unicode character at given position in the
* String by looking into the UTF-16 code unit; that is equal to 1 for any
* non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
* returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
* representing non-BMP characters ([U+10000..U+10FFFF]).
*
* Examples:
* - '\u0020' => 1
* - '\u3020' => 1
* - '\uD835' => 2
* - '\uD835\uDDEF' => 2
* - '\uDDEF' => 2
*
* @param {string} str Non-empty string
* @param {number} pos Position in the string to look for one code unit
* @return {number} Number 1 or 2
*/
function getUTF16Length(str, pos) {
return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
}
/**
* Fully Unicode-enabled replacement for String#length
*
* @param {string} str Valid Unicode string
* @return {number} The number of Unicode characters in the string
*/
function strlen(str) {
// Call the native functions if there's no surrogate char
if (!hasSurrogateUnit(str)) {
return str.length;
}
var len = 0;
for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
len++;
}
return len;
}
/**
* Fully Unicode-enabled replacement for String#substr()
*
* @param {string} str Valid Unicode string
* @param {number} start Location in Unicode sequence to begin extracting
* @param {?number} length The number of Unicode characters to extract
* (default: to the end of the string)
* @return {string} Extracted sub-string
*/
function substr(str, start, length) {
start = start || 0;
length = length === undefined ? Infinity : length || 0;
// Call the native functions if there's no surrogate char
if (!hasSurrogateUnit(str)) {
return str.substr(start, length);
}
// Obvious cases
var size = str.length;
if (size <= 0 || start > size || length <= 0) {
return '';
}
// Find the actual starting position
var posA = 0;
if (start > 0) {
for (; start > 0 && posA < size; start--) {
posA += getUTF16Length(str, posA);
}
if (posA >= size) {
return '';
}
} else if (start < 0) {
for (posA = size; start < 0 && 0 < posA; start++) {
posA -= getUTF16Length(str, posA - 1);
}
if (posA < 0) {
posA = 0;
}
}
// Find the actual ending position
var posB = size;
if (length < size) {
for (posB = posA; length > 0 && posB < size; length--) {
posB += getUTF16Length(str, posB);
}
}
return str.substring(posA, posB);
}
/**
* Fully Unicode-enabled replacement for String#substring()
*
* @param {string} str Valid Unicode string
* @param {number} start Location in Unicode sequence to begin extracting
* @param {?number} end Location in Unicode sequence to end extracting
* (default: end of the string)
* @return {string} Extracted sub-string
*/
function substring(str, start, end) {
start = start || 0;
end = end === undefined ? Infinity : end || 0;
if (start < 0) {
start = 0;
}
if (end < 0) {
end = 0;
}
var length = Math.abs(end - start);
start = start < end ? start : end;
return substr(str, start, length);
}
/**
* Get a list of Unicode code-points from a String
*
* @param {string} str Valid Unicode string
* @return {array<number>} A list of code-points in [0..0x10FFFF]
*/
function getCodePoints(str) {
var codePoints = [];
for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
codePoints.push(str.codePointAt(pos));
}
return codePoints;
}
var UnicodeUtils = {
getCodePoints: getCodePoints,
getUTF16Length: getUTF16Length,
hasSurrogateUnit: hasSurrogateUnit,
isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
isSurrogatePair: isSurrogatePair,
strlen: strlen,
substring: substring,
substr: substr
};
module.exports = UnicodeUtils;

View File

@@ -0,0 +1,213 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule UnicodeUtils
* @typechecks
*/
/**
* Unicode-enabled replacesments for basic String functions.
*
* All the functions in this module assume that the input string is a valid
* UTF-16 encoding of a Unicode sequence. If it's not the case, the behavior
* will be undefined.
*
* WARNING: Since this module is typechecks-enforced, you may find new bugs
* when replacing normal String functions with ones provided here.
*/
'use strict';
const invariant = require('./invariant');
// These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
// surrogate code unit.
const SURROGATE_HIGH_START = 0xD800;
const SURROGATE_HIGH_END = 0xDBFF;
const SURROGATE_LOW_START = 0xDC00;
const SURROGATE_LOW_END = 0xDFFF;
const SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
/**
* @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
* @return {boolean} Whether code-unit is in a surrogate (hi/low) range
*/
function isCodeUnitInSurrogateRange(codeUnit) {
return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
}
/**
* Returns whether the two characters starting at `index` form a surrogate pair.
* For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
* (s, 1) returns false.
*
* @param {string} str
* @param {number} index
* @return {boolean}
*/
function isSurrogatePair(str, index) {
invariant(0 <= index && index < str.length, 'isSurrogatePair: Invalid index %s for string length %s.', index, str.length);
if (index + 1 === str.length) {
return false;
}
const first = str.charCodeAt(index);
const second = str.charCodeAt(index + 1);
return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
}
/**
* @param {string} str Non-empty string
* @return {boolean} True if the input includes any surrogate code units
*/
function hasSurrogateUnit(str) {
return SURROGATE_UNITS_REGEX.test(str);
}
/**
* Return the length of the original Unicode character at given position in the
* String by looking into the UTF-16 code unit; that is equal to 1 for any
* non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
* returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
* representing non-BMP characters ([U+10000..U+10FFFF]).
*
* Examples:
* - '\u0020' => 1
* - '\u3020' => 1
* - '\uD835' => 2
* - '\uD835\uDDEF' => 2
* - '\uDDEF' => 2
*
* @param {string} str Non-empty string
* @param {number} pos Position in the string to look for one code unit
* @return {number} Number 1 or 2
*/
function getUTF16Length(str, pos) {
return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
}
/**
* Fully Unicode-enabled replacement for String#length
*
* @param {string} str Valid Unicode string
* @return {number} The number of Unicode characters in the string
*/
function strlen(str) {
// Call the native functions if there's no surrogate char
if (!hasSurrogateUnit(str)) {
return str.length;
}
let len = 0;
for (let pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
len++;
}
return len;
}
/**
* Fully Unicode-enabled replacement for String#substr()
*
* @param {string} str Valid Unicode string
* @param {number} start Location in Unicode sequence to begin extracting
* @param {?number} length The number of Unicode characters to extract
* (default: to the end of the string)
* @return {string} Extracted sub-string
*/
function substr(str, start, length) {
start = start || 0;
length = length === undefined ? Infinity : length || 0;
// Call the native functions if there's no surrogate char
if (!hasSurrogateUnit(str)) {
return str.substr(start, length);
}
// Obvious cases
const size = str.length;
if (size <= 0 || start > size || length <= 0) {
return '';
}
// Find the actual starting position
let posA = 0;
if (start > 0) {
for (; start > 0 && posA < size; start--) {
posA += getUTF16Length(str, posA);
}
if (posA >= size) {
return '';
}
} else if (start < 0) {
for (posA = size; start < 0 && 0 < posA; start++) {
posA -= getUTF16Length(str, posA - 1);
}
if (posA < 0) {
posA = 0;
}
}
// Find the actual ending position
let posB = size;
if (length < size) {
for (posB = posA; length > 0 && posB < size; length--) {
posB += getUTF16Length(str, posB);
}
}
return str.substring(posA, posB);
}
/**
* Fully Unicode-enabled replacement for String#substring()
*
* @param {string} str Valid Unicode string
* @param {number} start Location in Unicode sequence to begin extracting
* @param {?number} end Location in Unicode sequence to end extracting
* (default: end of the string)
* @return {string} Extracted sub-string
*/
function substring(str, start, end) {
start = start || 0;
end = end === undefined ? Infinity : end || 0;
if (start < 0) {
start = 0;
}
if (end < 0) {
end = 0;
}
const length = Math.abs(end - start);
start = start < end ? start : end;
return substr(str, start, length);
}
/**
* Get a list of Unicode code-points from a String
*
* @param {string} str Valid Unicode string
* @return {array<number>} A list of code-points in [0..0x10FFFF]
*/
function getCodePoints(str) {
const codePoints = [];
for (let pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
codePoints.push(str.codePointAt(pos));
}
return codePoints;
}
const UnicodeUtils = {
getCodePoints: getCodePoints,
getUTF16Length: getUTF16Length,
hasSurrogateUnit: hasSurrogateUnit,
isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
isSurrogatePair: isSurrogatePair,
strlen: strlen,
substring: substring,
substr: substr
};
module.exports = UnicodeUtils;

View File

@@ -0,0 +1,227 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
/**
* Unicode-enabled extra utility functions not always needed.
*/
'use strict';
var UnicodeUtils = require('./UnicodeUtils');
/**
* @param {number} codePoint Valid Unicode code-point
* @param {number} len Zero-padded minimum width of result
* @return {string} A zero-padded hexadecimal string (00XXXX)
*/
function zeroPaddedHex(codePoint, len) {
var codePointHex = codePoint.toString(16).toUpperCase();
var numZeros = Math.max(0, len - codePointHex.length);
var result = '';
for (var i = 0; i < numZeros; i++) {
result += '0';
}
result += codePointHex;
return result;
}
/**
* @param {number} codePoint Valid Unicode code-point
* @return {string} A formatted Unicode code-point string
* of the format U+XXXX, U+XXXXX, or U+XXXXXX
*/
function formatCodePoint(codePoint) {
codePoint = codePoint || 0; // NaN --> 0
var formatted = '';
if (codePoint <= 0xFFFF) {
formatted = zeroPaddedHex(codePoint, 4);
} else {
formatted = codePoint.toString(16).toUpperCase();
}
return 'U+' + formatted;
}
/**
* Get a list of formatted (string) Unicode code-points from a String
*
* @param {string} str Valid Unicode string
* @return {array<string>} A list of formatted code-point strings
*/
function getCodePointsFormatted(str) {
var codePoints = UnicodeUtils.getCodePoints(str);
return codePoints.map(formatCodePoint);
}
var specialEscape = {
0x07: '\\a',
0x08: '\\b',
0x0C: '\\f',
0x0A: '\\n',
0x0D: '\\r',
0x09: '\\t',
0x0B: '\\v',
0x22: '\\"',
0x5c: '\\\\'
};
/**
* Returns a double-quoted PHP string with all non-printable and
* non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function phpEscape(s) {
var result = '"';
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = UnicodeUtils.getCodePoints(s)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var cp = _step.value;
var special = specialEscape[cp];
if (special !== undefined) {
result += special;
} else if (cp >= 0x20 && cp <= 0x7e) {
result += String.fromCodePoint(cp);
} else if (cp <= 0xFFFF) {
result += '\\u{' + zeroPaddedHex(cp, 4) + '}';
} else {
result += '\\u{' + zeroPaddedHex(cp, 6) + '}';
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
result += '"';
return result;
}
/**
* Returns a double-quoted Java or JavaScript string with all
* non-printable and non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function jsEscape(s) {
var result = '"';
for (var i = 0; i < s.length; i++) {
var cp = s.charCodeAt(i);
var special = specialEscape[cp];
if (special !== undefined) {
result += special;
} else if (cp >= 0x20 && cp <= 0x7e) {
result += String.fromCodePoint(cp);
} else {
result += '\\u' + zeroPaddedHex(cp, 4);
}
}
result += '"';
return result;
}
function c11Escape(s) {
var result = '';
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = UnicodeUtils.getCodePoints(s)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var cp = _step2.value;
var special = specialEscape[cp];
if (special !== undefined) {
result += special;
} else if (cp >= 0x20 && cp <= 0x7e) {
result += String.fromCodePoint(cp);
} else if (cp <= 0xFFFF) {
result += '\\u' + zeroPaddedHex(cp, 4);
} else {
result += '\\U' + zeroPaddedHex(cp, 8);
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2['return']) {
_iterator2['return']();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return result;
}
/**
* Returns a double-quoted C string with all non-printable and
* non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function cEscape(s) {
return 'u8"' + c11Escape(s) + '"';
}
/**
* Returns a double-quoted Objective-C string with all non-printable
* and non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function objcEscape(s) {
return '@"' + c11Escape(s) + '"';
}
/**
* Returns a double-quoted Python string with all non-printable
* and non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function pyEscape(s) {
return 'u"' + c11Escape(s) + '"';
}
var UnicodeUtilsExtra = {
formatCodePoint: formatCodePoint,
getCodePointsFormatted: getCodePointsFormatted,
zeroPaddedHex: zeroPaddedHex,
phpEscape: phpEscape,
jsEscape: jsEscape,
cEscape: cEscape,
objcEscape: objcEscape,
pyEscape: pyEscape
};
module.exports = UnicodeUtilsExtra;

View File

@@ -0,0 +1,184 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule UnicodeUtilsExtra
* @typechecks
*/
/**
* Unicode-enabled extra utility functions not always needed.
*/
'use strict';
const UnicodeUtils = require('./UnicodeUtils');
/**
* @param {number} codePoint Valid Unicode code-point
* @param {number} len Zero-padded minimum width of result
* @return {string} A zero-padded hexadecimal string (00XXXX)
*/
function zeroPaddedHex(codePoint, len) {
let codePointHex = codePoint.toString(16).toUpperCase();
let numZeros = Math.max(0, len - codePointHex.length);
var result = '';
for (var i = 0; i < numZeros; i++) {
result += '0';
}
result += codePointHex;
return result;
}
/**
* @param {number} codePoint Valid Unicode code-point
* @return {string} A formatted Unicode code-point string
* of the format U+XXXX, U+XXXXX, or U+XXXXXX
*/
function formatCodePoint(codePoint) {
codePoint = codePoint || 0; // NaN --> 0
var formatted = '';
if (codePoint <= 0xFFFF) {
formatted = zeroPaddedHex(codePoint, 4);
} else {
formatted = codePoint.toString(16).toUpperCase();
}
return 'U+' + formatted;
}
/**
* Get a list of formatted (string) Unicode code-points from a String
*
* @param {string} str Valid Unicode string
* @return {array<string>} A list of formatted code-point strings
*/
function getCodePointsFormatted(str) {
const codePoints = UnicodeUtils.getCodePoints(str);
return codePoints.map(formatCodePoint);
}
const specialEscape = {
0x07: '\\a',
0x08: '\\b',
0x0C: '\\f',
0x0A: '\\n',
0x0D: '\\r',
0x09: '\\t',
0x0B: '\\v',
0x22: '\\"',
0x5c: '\\\\'
};
/**
* Returns a double-quoted PHP string with all non-printable and
* non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function phpEscape(s) {
var result = '"';
for (let cp of UnicodeUtils.getCodePoints(s)) {
let special = specialEscape[cp];
if (special !== undefined) {
result += special;
} else if (cp >= 0x20 && cp <= 0x7e) {
result += String.fromCodePoint(cp);
} else if (cp <= 0xFFFF) {
result += '\\u{' + zeroPaddedHex(cp, 4) + '}';
} else {
result += '\\u{' + zeroPaddedHex(cp, 6) + '}';
}
}
result += '"';
return result;
}
/**
* Returns a double-quoted Java or JavaScript string with all
* non-printable and non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function jsEscape(s) {
var result = '"';
for (var i = 0; i < s.length; i++) {
let cp = s.charCodeAt(i);
let special = specialEscape[cp];
if (special !== undefined) {
result += special;
} else if (cp >= 0x20 && cp <= 0x7e) {
result += String.fromCodePoint(cp);
} else {
result += '\\u' + zeroPaddedHex(cp, 4);
}
}
result += '"';
return result;
}
function c11Escape(s) {
var result = '';
for (let cp of UnicodeUtils.getCodePoints(s)) {
let special = specialEscape[cp];
if (special !== undefined) {
result += special;
} else if (cp >= 0x20 && cp <= 0x7e) {
result += String.fromCodePoint(cp);
} else if (cp <= 0xFFFF) {
result += '\\u' + zeroPaddedHex(cp, 4);
} else {
result += '\\U' + zeroPaddedHex(cp, 8);
}
}
return result;
}
/**
* Returns a double-quoted C string with all non-printable and
* non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function cEscape(s) {
return 'u8"' + c11Escape(s) + '"';
}
/**
* Returns a double-quoted Objective-C string with all non-printable
* and non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function objcEscape(s) {
return '@"' + c11Escape(s) + '"';
}
/**
* Returns a double-quoted Python string with all non-printable
* and non-US-ASCII sequences escaped.
*
* @param {string} str Valid Unicode string
* @return {string} Double-quoted string with Unicode sequences escaped
*/
function pyEscape(s) {
return 'u"' + c11Escape(s) + '"';
}
const UnicodeUtilsExtra = {
formatCodePoint: formatCodePoint,
getCodePointsFormatted: getCodePointsFormatted,
zeroPaddedHex: zeroPaddedHex,
phpEscape: phpEscape,
jsEscape: jsEscape,
cEscape: cEscape,
objcEscape: objcEscape,
pyEscape: pyEscape
};
module.exports = UnicodeUtilsExtra;

View File

@@ -0,0 +1,239 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
var UserAgentData = require('./UserAgentData');
var VersionRange = require('./VersionRange');
var mapObject = require('./mapObject');
var memoizeStringOnly = require('./memoizeStringOnly');
/**
* Checks to see whether `name` and `version` satisfy `query`.
*
* @param {string} name Name of the browser, device, engine or platform
* @param {?string} version Version of the browser, engine or platform
* @param {string} query Query of form "Name [range expression]"
* @param {?function} normalizer Optional pre-processor for range expression
* @return {boolean}
*/
function compare(name, version, query, normalizer) {
// check for exact match with no version
if (name === query) {
return true;
}
// check for non-matching names
if (!query.startsWith(name)) {
return false;
}
// full comparison with version
var range = query.slice(name.length);
if (version) {
range = normalizer ? normalizer(range) : range;
return VersionRange.contains(range, version);
}
return false;
}
/**
* Normalizes `version` by stripping any "NT" prefix, but only on the Windows
* platform.
*
* Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
*
* @param {string} version
* @return {string}
*/
function normalizePlatformVersion(version) {
if (UserAgentData.platformName === 'Windows') {
return version.replace(/^\s*NT/, '');
}
return version;
}
/**
* Provides client-side access to the authoritative PHP-generated User Agent
* information supplied by the server.
*/
var UserAgent = {
/**
* Check if the User Agent browser matches `query`.
*
* `query` should be a string like "Chrome" or "Chrome > 33".
*
* Valid browser names include:
*
* - ACCESS NetFront
* - AOL
* - Amazon Silk
* - Android
* - BlackBerry
* - BlackBerry PlayBook
* - Chrome
* - Chrome for iOS
* - Chrome frame
* - Facebook PHP SDK
* - Facebook for iOS
* - Firefox
* - IE
* - IE Mobile
* - Mobile Safari
* - Motorola Internet Browser
* - Nokia
* - Openwave Mobile Browser
* - Opera
* - Opera Mini
* - Opera Mobile
* - Safari
* - UIWebView
* - Unknown
* - webOS
* - etc...
*
* An authoritative list can be found in the PHP `BrowserDetector` class and
* related classes in the same file (see calls to `new UserAgentBrowser` here:
* https://fburl.com/50728104).
*
* @note Function results are memoized
*
* @param {string} query Query of the form "Name [range expression]"
* @return {boolean}
*/
isBrowser: function isBrowser(query) {
return compare(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
},
/**
* Check if the User Agent browser uses a 32 or 64 bit architecture.
*
* @note Function results are memoized
*
* @param {string} query Query of the form "32" or "64".
* @return {boolean}
*/
isBrowserArchitecture: function isBrowserArchitecture(query) {
return compare(UserAgentData.browserArchitecture, null, query);
},
/**
* Check if the User Agent device matches `query`.
*
* `query` should be a string like "iPhone" or "iPad".
*
* Valid device names include:
*
* - Kindle
* - Kindle Fire
* - Unknown
* - iPad
* - iPhone
* - iPod
* - etc...
*
* An authoritative list can be found in the PHP `DeviceDetector` class and
* related classes in the same file (see calls to `new UserAgentDevice` here:
* https://fburl.com/50728332).
*
* @note Function results are memoized
*
* @param {string} query Query of the form "Name"
* @return {boolean}
*/
isDevice: function isDevice(query) {
return compare(UserAgentData.deviceName, null, query);
},
/**
* Check if the User Agent rendering engine matches `query`.
*
* `query` should be a string like "WebKit" or "WebKit >= 537".
*
* Valid engine names include:
*
* - Gecko
* - Presto
* - Trident
* - WebKit
* - etc...
*
* An authoritative list can be found in the PHP `RenderingEngineDetector`
* class related classes in the same file (see calls to `new
* UserAgentRenderingEngine` here: https://fburl.com/50728617).
*
* @note Function results are memoized
*
* @param {string} query Query of the form "Name [range expression]"
* @return {boolean}
*/
isEngine: function isEngine(query) {
return compare(UserAgentData.engineName, UserAgentData.engineVersion, query);
},
/**
* Check if the User Agent platform matches `query`.
*
* `query` should be a string like "Windows" or "iOS 5 - 6".
*
* Valid platform names include:
*
* - Android
* - BlackBerry OS
* - Java ME
* - Linux
* - Mac OS X
* - Mac OS X Calendar
* - Mac OS X Internet Account
* - Symbian
* - SymbianOS
* - Windows
* - Windows Mobile
* - Windows Phone
* - iOS
* - iOS Facebook Integration Account
* - iOS Facebook Social Sharing UI
* - webOS
* - Chrome OS
* - etc...
*
* An authoritative list can be found in the PHP `PlatformDetector` class and
* related classes in the same file (see calls to `new UserAgentPlatform`
* here: https://fburl.com/50729226).
*
* @note Function results are memoized
*
* @param {string} query Query of the form "Name [range expression]"
* @return {boolean}
*/
isPlatform: function isPlatform(query) {
return compare(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
},
/**
* Check if the User Agent platform is a 32 or 64 bit architecture.
*
* @note Function results are memoized
*
* @param {string} query Query of the form "32" or "64".
* @return {boolean}
*/
isPlatformArchitecture: function isPlatformArchitecture(query) {
return compare(UserAgentData.platformArchitecture, null, query);
}
};
module.exports = mapObject(UserAgent, memoizeStringOnly);

View File

@@ -0,0 +1,236 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule UserAgent
*/
'use strict';
const UserAgentData = require('./UserAgentData');
const VersionRange = require('./VersionRange');
const mapObject = require('./mapObject');
const memoizeStringOnly = require('./memoizeStringOnly');
/**
* Checks to see whether `name` and `version` satisfy `query`.
*
* @param {string} name Name of the browser, device, engine or platform
* @param {?string} version Version of the browser, engine or platform
* @param {string} query Query of form "Name [range expression]"
* @param {?function} normalizer Optional pre-processor for range expression
* @return {boolean}
*/
function compare(name, version, query, normalizer) {
// check for exact match with no version
if (name === query) {
return true;
}
// check for non-matching names
if (!query.startsWith(name)) {
return false;
}
// full comparison with version
let range = query.slice(name.length);
if (version) {
range = normalizer ? normalizer(range) : range;
return VersionRange.contains(range, version);
}
return false;
}
/**
* Normalizes `version` by stripping any "NT" prefix, but only on the Windows
* platform.
*
* Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
*
* @param {string} version
* @return {string}
*/
function normalizePlatformVersion(version) {
if (UserAgentData.platformName === 'Windows') {
return version.replace(/^\s*NT/, '');
}
return version;
}
/**
* Provides client-side access to the authoritative PHP-generated User Agent
* information supplied by the server.
*/
const UserAgent = {
/**
* Check if the User Agent browser matches `query`.
*
* `query` should be a string like "Chrome" or "Chrome > 33".
*
* Valid browser names include:
*
* - ACCESS NetFront
* - AOL
* - Amazon Silk
* - Android
* - BlackBerry
* - BlackBerry PlayBook
* - Chrome
* - Chrome for iOS
* - Chrome frame
* - Facebook PHP SDK
* - Facebook for iOS
* - Firefox
* - IE
* - IE Mobile
* - Mobile Safari
* - Motorola Internet Browser
* - Nokia
* - Openwave Mobile Browser
* - Opera
* - Opera Mini
* - Opera Mobile
* - Safari
* - UIWebView
* - Unknown
* - webOS
* - etc...
*
* An authoritative list can be found in the PHP `BrowserDetector` class and
* related classes in the same file (see calls to `new UserAgentBrowser` here:
* https://fburl.com/50728104).
*
* @note Function results are memoized
*
* @param {string} query Query of the form "Name [range expression]"
* @return {boolean}
*/
isBrowser(query) {
return compare(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
},
/**
* Check if the User Agent browser uses a 32 or 64 bit architecture.
*
* @note Function results are memoized
*
* @param {string} query Query of the form "32" or "64".
* @return {boolean}
*/
isBrowserArchitecture(query) {
return compare(UserAgentData.browserArchitecture, null, query);
},
/**
* Check if the User Agent device matches `query`.
*
* `query` should be a string like "iPhone" or "iPad".
*
* Valid device names include:
*
* - Kindle
* - Kindle Fire
* - Unknown
* - iPad
* - iPhone
* - iPod
* - etc...
*
* An authoritative list can be found in the PHP `DeviceDetector` class and
* related classes in the same file (see calls to `new UserAgentDevice` here:
* https://fburl.com/50728332).
*
* @note Function results are memoized
*
* @param {string} query Query of the form "Name"
* @return {boolean}
*/
isDevice(query) {
return compare(UserAgentData.deviceName, null, query);
},
/**
* Check if the User Agent rendering engine matches `query`.
*
* `query` should be a string like "WebKit" or "WebKit >= 537".
*
* Valid engine names include:
*
* - Gecko
* - Presto
* - Trident
* - WebKit
* - etc...
*
* An authoritative list can be found in the PHP `RenderingEngineDetector`
* class related classes in the same file (see calls to `new
* UserAgentRenderingEngine` here: https://fburl.com/50728617).
*
* @note Function results are memoized
*
* @param {string} query Query of the form "Name [range expression]"
* @return {boolean}
*/
isEngine(query) {
return compare(UserAgentData.engineName, UserAgentData.engineVersion, query);
},
/**
* Check if the User Agent platform matches `query`.
*
* `query` should be a string like "Windows" or "iOS 5 - 6".
*
* Valid platform names include:
*
* - Android
* - BlackBerry OS
* - Java ME
* - Linux
* - Mac OS X
* - Mac OS X Calendar
* - Mac OS X Internet Account
* - Symbian
* - SymbianOS
* - Windows
* - Windows Mobile
* - Windows Phone
* - iOS
* - iOS Facebook Integration Account
* - iOS Facebook Social Sharing UI
* - webOS
* - Chrome OS
* - etc...
*
* An authoritative list can be found in the PHP `PlatformDetector` class and
* related classes in the same file (see calls to `new UserAgentPlatform`
* here: https://fburl.com/50729226).
*
* @note Function results are memoized
*
* @param {string} query Query of the form "Name [range expression]"
* @return {boolean}
*/
isPlatform(query) {
return compare(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
},
/**
* Check if the User Agent platform is a 32 or 64 bit architecture.
*
* @note Function results are memoized
*
* @param {string} query Query of the form "32" or "64".
* @return {boolean}
*/
isPlatformArchitecture(query) {
return compare(UserAgentData.platformArchitecture, null, query);
}
};
module.exports = mapObject(UserAgent, memoizeStringOnly);

View File

@@ -0,0 +1,80 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/**
* Usage note:
* This module makes a best effort to export the same data we would internally.
* At Facebook we use a server-generated module that does the parsing and
* exports the data for the client to use. We can't rely on a server-side
* implementation in open source so instead we make use of an open source
* library to do the heavy lifting and then make some adjustments as necessary.
* It's likely there will be some differences. Some we can smooth over.
* Others are going to be harder.
*/
'use strict';
var UAParser = require('ua-parser-js');
var UNKNOWN = 'Unknown';
var PLATFORM_MAP = {
'Mac OS': 'Mac OS X'
};
/**
* Convert from UAParser platform name to what we expect.
*/
function convertPlatformName(name) {
return PLATFORM_MAP[name] || name;
}
/**
* Get the version number in parts. This is very naive. We actually get major
* version as a part of UAParser already, which is generally good enough, but
* let's get the minor just in case.
*/
function getBrowserVersion(version) {
if (!version) {
return {
major: '',
minor: ''
};
}
var parts = version.split('.');
return {
major: parts[0],
minor: parts[1]
};
}
/**
* Get the UA data fom UAParser and then convert it to the format we're
* expecting for our APIS.
*/
var parser = new UAParser();
var results = parser.getResult();
// Do some conversion first.
var browserVersionData = getBrowserVersion(results.browser.version);
var uaData = {
browserArchitecture: results.cpu.architecture || UNKNOWN,
browserFullVersion: results.browser.version || UNKNOWN,
browserMinorVersion: browserVersionData.minor || UNKNOWN,
browserName: results.browser.name || UNKNOWN,
browserVersion: results.browser.major || UNKNOWN,
deviceName: results.device.model || UNKNOWN,
engineName: results.engine.name || UNKNOWN,
engineVersion: results.engine.version || UNKNOWN,
platformArchitecture: results.cpu.architecture || UNKNOWN,
platformName: convertPlatformName(results.os.name) || UNKNOWN,
platformVersion: results.os.version || UNKNOWN,
platformFullVersion: results.os.version || UNKNOWN
};
module.exports = uaData;

View File

@@ -0,0 +1,81 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule UserAgentData
*/
/**
* Usage note:
* This module makes a best effort to export the same data we would internally.
* At Facebook we use a server-generated module that does the parsing and
* exports the data for the client to use. We can't rely on a server-side
* implementation in open source so instead we make use of an open source
* library to do the heavy lifting and then make some adjustments as necessary.
* It's likely there will be some differences. Some we can smooth over.
* Others are going to be harder.
*/
'use strict';
var UAParser = require('ua-parser-js');
var UNKNOWN = 'Unknown';
var PLATFORM_MAP = {
'Mac OS': 'Mac OS X'
};
/**
* Convert from UAParser platform name to what we expect.
*/
function convertPlatformName(name) {
return PLATFORM_MAP[name] || name;
}
/**
* Get the version number in parts. This is very naive. We actually get major
* version as a part of UAParser already, which is generally good enough, but
* let's get the minor just in case.
*/
function getBrowserVersion(version) {
if (!version) {
return {
major: '',
minor: ''
};
}
var parts = version.split('.');
return {
major: parts[0],
minor: parts[1]
};
}
/**
* Get the UA data fom UAParser and then convert it to the format we're
* expecting for our APIS.
*/
var parser = new UAParser();
var results = parser.getResult();
// Do some conversion first.
var browserVersionData = getBrowserVersion(results.browser.version);
var uaData = {
browserArchitecture: results.cpu.architecture || UNKNOWN,
browserFullVersion: results.browser.version || UNKNOWN,
browserMinorVersion: browserVersionData.minor || UNKNOWN,
browserName: results.browser.name || UNKNOWN,
browserVersion: results.browser.major || UNKNOWN,
deviceName: results.device.model || UNKNOWN,
engineName: results.engine.name || UNKNOWN,
engineVersion: results.engine.version || UNKNOWN,
platformArchitecture: results.cpu.architecture || UNKNOWN,
platformName: convertPlatformName(results.os.name) || UNKNOWN,
platformVersion: results.os.version || UNKNOWN,
platformFullVersion: results.os.version || UNKNOWN
};
module.exports = uaData;

View File

@@ -0,0 +1,380 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
var invariant = require('./invariant');
var componentRegex = /\./;
var orRegex = /\|\|/;
var rangeRegex = /\s+\-\s+/;
var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
var numericRegex = /^(\d*)(.*)/;
/**
* Splits input `range` on "||" and returns true if any subrange matches
* `version`.
*
* @param {string} range
* @param {string} version
* @returns {boolean}
*/
function checkOrExpression(range, version) {
var expressions = range.split(orRegex);
if (expressions.length > 1) {
return expressions.some(function (range) {
return VersionRange.contains(range, version);
});
} else {
range = expressions[0].trim();
return checkRangeExpression(range, version);
}
}
/**
* Splits input `range` on " - " (the surrounding whitespace is required) and
* returns true if version falls between the two operands.
*
* @param {string} range
* @param {string} version
* @returns {boolean}
*/
function checkRangeExpression(range, version) {
var expressions = range.split(rangeRegex);
!(expressions.length > 0 && expressions.length <= 2) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'the "-" operator expects exactly 2 operands') : invariant(false) : void 0;
if (expressions.length === 1) {
return checkSimpleExpression(expressions[0], version);
} else {
var startVersion = expressions[0],
endVersion = expressions[1];
!(isSimpleVersion(startVersion) && isSimpleVersion(endVersion)) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'operands to the "-" operator must be simple (no modifiers)') : invariant(false) : void 0;
return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
}
}
/**
* Checks if `range` matches `version`. `range` should be a "simple" range (ie.
* not a compound range using the " - " or "||" operators).
*
* @param {string} range
* @param {string} version
* @returns {boolean}
*/
function checkSimpleExpression(range, version) {
range = range.trim();
if (range === '') {
return true;
}
var versionComponents = version.split(componentRegex);
var _getModifierAndCompon = getModifierAndComponents(range),
modifier = _getModifierAndCompon.modifier,
rangeComponents = _getModifierAndCompon.rangeComponents;
switch (modifier) {
case '<':
return checkLessThan(versionComponents, rangeComponents);
case '<=':
return checkLessThanOrEqual(versionComponents, rangeComponents);
case '>=':
return checkGreaterThanOrEqual(versionComponents, rangeComponents);
case '>':
return checkGreaterThan(versionComponents, rangeComponents);
case '~':
case '~>':
return checkApproximateVersion(versionComponents, rangeComponents);
default:
return checkEqual(versionComponents, rangeComponents);
}
}
/**
* Checks whether `a` is less than `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkLessThan(a, b) {
return compareComponents(a, b) === -1;
}
/**
* Checks whether `a` is less than or equal to `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkLessThanOrEqual(a, b) {
var result = compareComponents(a, b);
return result === -1 || result === 0;
}
/**
* Checks whether `a` is equal to `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkEqual(a, b) {
return compareComponents(a, b) === 0;
}
/**
* Checks whether `a` is greater than or equal to `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkGreaterThanOrEqual(a, b) {
var result = compareComponents(a, b);
return result === 1 || result === 0;
}
/**
* Checks whether `a` is greater than `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkGreaterThan(a, b) {
return compareComponents(a, b) === 1;
}
/**
* Checks whether `a` is "reasonably close" to `b` (as described in
* https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
* then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkApproximateVersion(a, b) {
var lowerBound = b.slice();
var upperBound = b.slice();
if (upperBound.length > 1) {
upperBound.pop();
}
var lastIndex = upperBound.length - 1;
var numeric = parseInt(upperBound[lastIndex], 10);
if (isNumber(numeric)) {
upperBound[lastIndex] = numeric + 1 + '';
}
return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
}
/**
* Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
* components from `range`.
*
* For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
* `">="` and `components` of `[1, 2, 3]`.
*
* @param {string} range
* @returns {object}
*/
function getModifierAndComponents(range) {
var rangeComponents = range.split(componentRegex);
var matches = rangeComponents[0].match(modifierRegex);
!matches ? process.env.NODE_ENV !== 'production' ? invariant(false, 'expected regex to match but it did not') : invariant(false) : void 0;
return {
modifier: matches[1],
rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
};
}
/**
* Determines if `number` is a number.
*
* @param {mixed} number
* @returns {boolean}
*/
function isNumber(number) {
return !isNaN(number) && isFinite(number);
}
/**
* Tests whether `range` is a "simple" version number without any modifiers
* (">", "~" etc).
*
* @param {string} range
* @returns {boolean}
*/
function isSimpleVersion(range) {
return !getModifierAndComponents(range).modifier;
}
/**
* Zero-pads array `array` until it is at least `length` long.
*
* @param {array} array
* @param {number} length
*/
function zeroPad(array, length) {
for (var i = array.length; i < length; i++) {
array[i] = '0';
}
}
/**
* Normalizes `a` and `b` in preparation for comparison by doing the following:
*
* - zero-pads `a` and `b`
* - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
* in both `a` and `b`
* - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
* and all of its successors in `a`
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {array<array<string>>}
*/
function normalizeVersions(a, b) {
a = a.slice();
b = b.slice();
zeroPad(a, b.length);
// mark "x" and "*" components as equal
for (var i = 0; i < b.length; i++) {
var matches = b[i].match(/^[x*]$/i);
if (matches) {
b[i] = a[i] = '0';
// final "*" greedily zeros all remaining components
if (matches[0] === '*' && i === b.length - 1) {
for (var j = i; j < a.length; j++) {
a[j] = '0';
}
}
}
}
zeroPad(b, a.length);
return [a, b];
}
/**
* Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
*
* For example, `10-alpha` is greater than `2-beta`.
*
* @param {string} a
* @param {string} b
* @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
* or greater than `b`, respectively
*/
function compareNumeric(a, b) {
var aPrefix = a.match(numericRegex)[1];
var bPrefix = b.match(numericRegex)[1];
var aNumeric = parseInt(aPrefix, 10);
var bNumeric = parseInt(bPrefix, 10);
if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
return compare(aNumeric, bNumeric);
} else {
return compare(a, b);
}
}
/**
* Returns the ordering of `a` and `b`.
*
* @param {string|number} a
* @param {string|number} b
* @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
* or greater than `b`, respectively
*/
function compare(a, b) {
!(typeof a === typeof b) ? process.env.NODE_ENV !== 'production' ? invariant(false, '"a" and "b" must be of the same type') : invariant(false) : void 0;
if (a > b) {
return 1;
} else if (a < b) {
return -1;
} else {
return 0;
}
}
/**
* Compares arrays of version components.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
* or greater than `b`, respectively
*/
function compareComponents(a, b) {
var _normalizeVersions = normalizeVersions(a, b),
aNormalized = _normalizeVersions[0],
bNormalized = _normalizeVersions[1];
for (var i = 0; i < bNormalized.length; i++) {
var result = compareNumeric(aNormalized[i], bNormalized[i]);
if (result) {
return result;
}
}
return 0;
}
var VersionRange = {
/**
* Checks whether `version` satisfies the `range` specification.
*
* We support a subset of the expressions defined in
* https://www.npmjs.org/doc/misc/semver.html:
*
* version Must match version exactly
* =version Same as just version
* >version Must be greater than version
* >=version Must be greater than or equal to version
* <version Must be less than version
* <=version Must be less than or equal to version
* ~version Must be at least version, but less than the next significant
* revision above version:
* "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
* ~>version Equivalent to ~version
* 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
* anything
* 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
* "greedy" wildcard, so will match any number of additional
* components:
* "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
* * Any version
* "" (Empty string) Same as *
* v1 - v2 Equivalent to ">= v1 and <= v2"
* r1 || r2 Passes if either r1 or r2 are satisfied
*
* @param {string} range
* @param {string} version
* @returns {boolean}
*/
contains: function contains(range, version) {
return checkOrExpression(range.trim(), version.trim());
}
};
module.exports = VersionRange;

View File

@@ -0,0 +1,371 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule VersionRange
*/
'use strict';
const invariant = require('./invariant');
const componentRegex = /\./;
const orRegex = /\|\|/;
const rangeRegex = /\s+\-\s+/;
const modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
const numericRegex = /^(\d*)(.*)/;
/**
* Splits input `range` on "||" and returns true if any subrange matches
* `version`.
*
* @param {string} range
* @param {string} version
* @returns {boolean}
*/
function checkOrExpression(range, version) {
const expressions = range.split(orRegex);
if (expressions.length > 1) {
return expressions.some(range => VersionRange.contains(range, version));
} else {
range = expressions[0].trim();
return checkRangeExpression(range, version);
}
}
/**
* Splits input `range` on " - " (the surrounding whitespace is required) and
* returns true if version falls between the two operands.
*
* @param {string} range
* @param {string} version
* @returns {boolean}
*/
function checkRangeExpression(range, version) {
const expressions = range.split(rangeRegex);
invariant(expressions.length > 0 && expressions.length <= 2, 'the "-" operator expects exactly 2 operands');
if (expressions.length === 1) {
return checkSimpleExpression(expressions[0], version);
} else {
const [startVersion, endVersion] = expressions;
invariant(isSimpleVersion(startVersion) && isSimpleVersion(endVersion), 'operands to the "-" operator must be simple (no modifiers)');
return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
}
}
/**
* Checks if `range` matches `version`. `range` should be a "simple" range (ie.
* not a compound range using the " - " or "||" operators).
*
* @param {string} range
* @param {string} version
* @returns {boolean}
*/
function checkSimpleExpression(range, version) {
range = range.trim();
if (range === '') {
return true;
}
const versionComponents = version.split(componentRegex);
const { modifier, rangeComponents } = getModifierAndComponents(range);
switch (modifier) {
case '<':
return checkLessThan(versionComponents, rangeComponents);
case '<=':
return checkLessThanOrEqual(versionComponents, rangeComponents);
case '>=':
return checkGreaterThanOrEqual(versionComponents, rangeComponents);
case '>':
return checkGreaterThan(versionComponents, rangeComponents);
case '~':
case '~>':
return checkApproximateVersion(versionComponents, rangeComponents);
default:
return checkEqual(versionComponents, rangeComponents);
}
}
/**
* Checks whether `a` is less than `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkLessThan(a, b) {
return compareComponents(a, b) === -1;
}
/**
* Checks whether `a` is less than or equal to `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkLessThanOrEqual(a, b) {
const result = compareComponents(a, b);
return result === -1 || result === 0;
}
/**
* Checks whether `a` is equal to `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkEqual(a, b) {
return compareComponents(a, b) === 0;
}
/**
* Checks whether `a` is greater than or equal to `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkGreaterThanOrEqual(a, b) {
const result = compareComponents(a, b);
return result === 1 || result === 0;
}
/**
* Checks whether `a` is greater than `b`.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkGreaterThan(a, b) {
return compareComponents(a, b) === 1;
}
/**
* Checks whether `a` is "reasonably close" to `b` (as described in
* https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
* then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {boolean}
*/
function checkApproximateVersion(a, b) {
const lowerBound = b.slice();
const upperBound = b.slice();
if (upperBound.length > 1) {
upperBound.pop();
}
const lastIndex = upperBound.length - 1;
const numeric = parseInt(upperBound[lastIndex], 10);
if (isNumber(numeric)) {
upperBound[lastIndex] = numeric + 1 + '';
}
return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
}
/**
* Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
* components from `range`.
*
* For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
* `">="` and `components` of `[1, 2, 3]`.
*
* @param {string} range
* @returns {object}
*/
function getModifierAndComponents(range) {
const rangeComponents = range.split(componentRegex);
const matches = rangeComponents[0].match(modifierRegex);
invariant(matches, 'expected regex to match but it did not');
return {
modifier: matches[1],
rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
};
}
/**
* Determines if `number` is a number.
*
* @param {mixed} number
* @returns {boolean}
*/
function isNumber(number) {
return !isNaN(number) && isFinite(number);
}
/**
* Tests whether `range` is a "simple" version number without any modifiers
* (">", "~" etc).
*
* @param {string} range
* @returns {boolean}
*/
function isSimpleVersion(range) {
return !getModifierAndComponents(range).modifier;
}
/**
* Zero-pads array `array` until it is at least `length` long.
*
* @param {array} array
* @param {number} length
*/
function zeroPad(array, length) {
for (let i = array.length; i < length; i++) {
array[i] = '0';
}
}
/**
* Normalizes `a` and `b` in preparation for comparison by doing the following:
*
* - zero-pads `a` and `b`
* - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
* in both `a` and `b`
* - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
* and all of its successors in `a`
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {array<array<string>>}
*/
function normalizeVersions(a, b) {
a = a.slice();
b = b.slice();
zeroPad(a, b.length);
// mark "x" and "*" components as equal
for (let i = 0; i < b.length; i++) {
const matches = b[i].match(/^[x*]$/i);
if (matches) {
b[i] = a[i] = '0';
// final "*" greedily zeros all remaining components
if (matches[0] === '*' && i === b.length - 1) {
for (let j = i; j < a.length; j++) {
a[j] = '0';
}
}
}
}
zeroPad(b, a.length);
return [a, b];
}
/**
* Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
*
* For example, `10-alpha` is greater than `2-beta`.
*
* @param {string} a
* @param {string} b
* @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
* or greater than `b`, respectively
*/
function compareNumeric(a, b) {
const aPrefix = a.match(numericRegex)[1];
const bPrefix = b.match(numericRegex)[1];
const aNumeric = parseInt(aPrefix, 10);
const bNumeric = parseInt(bPrefix, 10);
if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
return compare(aNumeric, bNumeric);
} else {
return compare(a, b);
}
}
/**
* Returns the ordering of `a` and `b`.
*
* @param {string|number} a
* @param {string|number} b
* @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
* or greater than `b`, respectively
*/
function compare(a, b) {
invariant(typeof a === typeof b, '"a" and "b" must be of the same type');
if (a > b) {
return 1;
} else if (a < b) {
return -1;
} else {
return 0;
}
}
/**
* Compares arrays of version components.
*
* @param {array<string>} a
* @param {array<string>} b
* @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
* or greater than `b`, respectively
*/
function compareComponents(a, b) {
const [aNormalized, bNormalized] = normalizeVersions(a, b);
for (let i = 0; i < bNormalized.length; i++) {
const result = compareNumeric(aNormalized[i], bNormalized[i]);
if (result) {
return result;
}
}
return 0;
}
var VersionRange = {
/**
* Checks whether `version` satisfies the `range` specification.
*
* We support a subset of the expressions defined in
* https://www.npmjs.org/doc/misc/semver.html:
*
* version Must match version exactly
* =version Same as just version
* >version Must be greater than version
* >=version Must be greater than or equal to version
* <version Must be less than version
* <=version Must be less than or equal to version
* ~version Must be at least version, but less than the next significant
* revision above version:
* "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
* ~>version Equivalent to ~version
* 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
* anything
* 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
* "greedy" wildcard, so will match any number of additional
* components:
* "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
* * Any version
* "" (Empty string) Same as *
* v1 - v2 Equivalent to ">= v1 and <= v2"
* r1 || r2 Passes if either r1 or r2 are satisfied
*
* @param {string} range
* @param {string} version
* @returns {boolean}
*/
contains(range, version) {
return checkOrExpression(range.trim(), version.trim());
}
};
module.exports = VersionRange;

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var ErrorUtils = jest.genMockFromModule('../ErrorUtils');
ErrorUtils.applyWithGuard.mockImplementation(function (callback, context, args) {
return callback.apply(context, args);
});
ErrorUtils.guard.mockImplementation(function (callback) {
return callback;
});
module.exports = ErrorUtils;

View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
module.exports = require.requireActual('../base62');

View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
module.exports = require.requireActual('../crc32');

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noflow
*/
'use strict';
var Deferred = require.requireActual('../Deferred');
function fetch(uri, options) {
var deferred = new Deferred();
fetch.mock.calls.push([uri, options]);
fetch.mock.deferreds.push(deferred);
return deferred.getPromise();
}
fetch.mock = {
calls: [],
deferreds: []
};
module.exports = fetch;

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @noflow
*/
'use strict';
var Deferred = require.requireActual('../Deferred');
function fetchWithRetries() {
var deferred = new Deferred();
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
fetchWithRetries.mock.calls.push(args);
fetchWithRetries.mock.deferreds.push(deferred);
return deferred.getPromise();
}
fetchWithRetries.mock = {
calls: [],
deferreds: []
};
module.exports = fetchWithRetries;

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
jest.dontMock('../nullthrows');
module.exports = require('../nullthrows');

View File

@@ -0,0 +1,39 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @preventMunge
*
*/
/**
* Checks whether a collection name (e.g. "Map" or "Set") has a native polyfill
* that is safe to be used.
*/
function shouldPolyfillES6Collection(collectionName) {
var Collection = global[collectionName];
if (Collection == null) {
return true;
}
// The iterator protocol depends on `Symbol.iterator`. If a collection is
// implemented, but `Symbol` is not, it's going to break iteration because
// we'll be using custom "@@iterator" instead, which is not implemented on
// native collections.
if (typeof global.Symbol !== 'function') {
return true;
}
var proto = Collection.prototype;
// These checks are adapted from es6-shim: https://fburl.com/34437854
// NOTE: `isCallableWithoutNew` and `!supportsSubclassing` are not checked
// because they make debugging with "break on exceptions" difficult.
return Collection == null || typeof Collection !== 'function' || typeof proto.clear !== 'function' || new Collection().size !== 0 || typeof proto.keys !== 'function' || typeof proto.forEach !== 'function';
}
module.exports = shouldPolyfillES6Collection;

View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule _shouldPolyfillES6Collection
* @preventMunge
* @flow
*/
/**
* Checks whether a collection name (e.g. "Map" or "Set") has a native polyfill
* that is safe to be used.
*/
function shouldPolyfillES6Collection(collectionName: string): boolean {
const Collection = global[collectionName];
if (Collection == null) {
return true;
}
// The iterator protocol depends on `Symbol.iterator`. If a collection is
// implemented, but `Symbol` is not, it's going to break iteration because
// we'll be using custom "@@iterator" instead, which is not implemented on
// native collections.
if (typeof global.Symbol !== 'function') {
return true;
}
const proto = Collection.prototype;
// These checks are adapted from es6-shim: https://fburl.com/34437854
// NOTE: `isCallableWithoutNew` and `!supportsSubclassing` are not checked
// because they make debugging with "break on exceptions" difficult.
return Collection == null || typeof Collection !== 'function' || typeof proto.clear !== 'function' || new Collection().size !== 0 || typeof proto.keys !== 'function' || typeof proto.forEach !== 'function';
}
module.exports = shouldPolyfillES6Collection;

View File

@@ -0,0 +1,106 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
var aStackPool = [];
var bStackPool = [];
/**
* Checks if two values are equal. Values may be primitives, arrays, or objects.
* Returns true if both arguments have the same keys and values.
*
* @see http://underscorejs.org
* @copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
* @license MIT
*/
function areEqual(a, b) {
var aStack = aStackPool.length ? aStackPool.pop() : [];
var bStack = bStackPool.length ? bStackPool.pop() : [];
var result = eq(a, b, aStack, bStack);
aStack.length = 0;
bStack.length = 0;
aStackPool.push(aStack);
bStackPool.push(bStack);
return result;
}
function eq(a, b, aStack, bStack) {
if (a === b) {
// Identical objects are equal. `0 === -0`, but they aren't identical.
return a !== 0 || 1 / a == 1 / b;
}
if (a == null || b == null) {
// a or b can be `null` or `undefined`
return false;
}
if (typeof a != 'object' || typeof b != 'object') {
return false;
}
var objToStr = Object.prototype.toString;
var className = objToStr.call(a);
if (className != objToStr.call(b)) {
return false;
}
switch (className) {
case '[object String]':
return a == String(b);
case '[object Number]':
return isNaN(a) || isNaN(b) ? false : a == Number(b);
case '[object Date]':
case '[object Boolean]':
return +a == +b;
case '[object RegExp]':
return a.source == b.source && a.global == b.global && a.multiline == b.multiline && a.ignoreCase == b.ignoreCase;
}
// Assume equality for cyclic structures.
var length = aStack.length;
while (length--) {
if (aStack[length] == a) {
return bStack[length] == b;
}
}
aStack.push(a);
bStack.push(b);
var size = 0;
// Recursively compare objects and arrays.
if (className === '[object Array]') {
size = a.length;
if (size !== b.length) {
return false;
}
// Deep compare the contents, ignoring non-numeric properties.
while (size--) {
if (!eq(a[size], b[size], aStack, bStack)) {
return false;
}
}
} else {
if (a.constructor !== b.constructor) {
return false;
}
if (a.hasOwnProperty('valueOf') && b.hasOwnProperty('valueOf')) {
return a.valueOf() == b.valueOf();
}
var keys = Object.keys(a);
if (keys.length != Object.keys(b).length) {
return false;
}
for (var i = 0; i < keys.length; i++) {
if (!eq(a[keys[i]], b[keys[i]], aStack, bStack)) {
return false;
}
}
}
aStack.pop();
bStack.pop();
return true;
}
module.exports = areEqual;

View File

@@ -0,0 +1,105 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule areEqual
* @flow
*/
const aStackPool = [];
const bStackPool = [];
/**
* Checks if two values are equal. Values may be primitives, arrays, or objects.
* Returns true if both arguments have the same keys and values.
*
* @see http://underscorejs.org
* @copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
* @license MIT
*/
function areEqual(a: any, b: any): boolean {
const aStack = aStackPool.length ? aStackPool.pop() : [];
const bStack = bStackPool.length ? bStackPool.pop() : [];
const result = eq(a, b, aStack, bStack);
aStack.length = 0;
bStack.length = 0;
aStackPool.push(aStack);
bStackPool.push(bStack);
return result;
}
function eq(a: any, b: any, aStack: Array<any>, bStack: Array<any>): boolean {
if (a === b) {
// Identical objects are equal. `0 === -0`, but they aren't identical.
return a !== 0 || 1 / a == 1 / b;
}
if (a == null || b == null) {
// a or b can be `null` or `undefined`
return false;
}
if (typeof a != 'object' || typeof b != 'object') {
return false;
}
const objToStr = Object.prototype.toString;
const className = objToStr.call(a);
if (className != objToStr.call(b)) {
return false;
}
switch (className) {
case '[object String]':
return a == String(b);
case '[object Number]':
return isNaN(a) || isNaN(b) ? false : a == Number(b);
case '[object Date]':
case '[object Boolean]':
return +a == +b;
case '[object RegExp]':
return a.source == b.source && a.global == b.global && a.multiline == b.multiline && a.ignoreCase == b.ignoreCase;
}
// Assume equality for cyclic structures.
let length = aStack.length;
while (length--) {
if (aStack[length] == a) {
return bStack[length] == b;
}
}
aStack.push(a);
bStack.push(b);
let size = 0;
// Recursively compare objects and arrays.
if (className === '[object Array]') {
size = a.length;
if (size !== b.length) {
return false;
}
// Deep compare the contents, ignoring non-numeric properties.
while (size--) {
if (!eq(a[size], b[size], aStack, bStack)) {
return false;
}
}
} else {
if (a.constructor !== b.constructor) {
return false;
}
if (a.hasOwnProperty('valueOf') && b.hasOwnProperty('valueOf')) {
return a.valueOf() == b.valueOf();
}
const keys = Object.keys(a);
if (keys.length != Object.keys(b).length) {
return false;
}
for (let i = 0; i < keys.length; i++) {
if (!eq(a[keys[i]], b[keys[i]], aStack, bStack)) {
return false;
}
}
}
aStack.pop();
bStack.pop();
return true;
}
module.exports = areEqual;

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
'use strict';
var BASE62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
function base62(number) {
if (!number) {
return '0';
}
var string = '';
while (number > 0) {
string = BASE62[number % 62] + string;
number = Math.floor(number / 62);
}
return string;
}
module.exports = base62;

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule base62
* @flow
*/
'use strict';
const BASE62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
function base62(number: number): string {
if (!number) {
return '0';
}
let string = '';
while (number > 0) {
string = BASE62[number % 62] + string;
number = Math.floor(number / 62);
}
return string;
}
module.exports = base62;

View File

@@ -0,0 +1,29 @@
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
var _hyphenPattern = /-(.)/g;
/**
* Camelcases a hyphenated string, for example:
*
* > camelize('background-color')
* < "backgroundColor"
*
* @param {string} string
* @return {string}
*/
function camelize(string) {
return string.replace(_hyphenPattern, function (_, character) {
return character.toUpperCase();
});
}
module.exports = camelize;

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule camelize
* @typechecks
*/
const _hyphenPattern = /-(.)/g;
/**
* Camelcases a hyphenated string, for example:
*
* > camelize('background-color')
* < "backgroundColor"
*
* @param {string} string
* @return {string}
*/
function camelize(string) {
return string.replace(_hyphenPattern, function (_, character) {
return character.toUpperCase();
});
}
module.exports = camelize;

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
'use strict';
var camelize = require('./camelize');
var msPattern = /^-ms-/;
/**
* Camelcases a hyphenated CSS property name, for example:
*
* > camelizeStyleName('background-color')
* < "backgroundColor"
* > camelizeStyleName('-moz-transition')
* < "MozTransition"
* > camelizeStyleName('-ms-transition')
* < "msTransition"
*
* As Andi Smith suggests
* (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix
* is converted to lowercase `ms`.
*
* @param {string} string
* @return {string}
*/
function camelizeStyleName(string) {
return camelize(string.replace(msPattern, 'ms-'));
}
module.exports = camelizeStyleName;

View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule camelizeStyleName
* @typechecks
*/
'use strict';
const camelize = require('./camelize');
const msPattern = /^-ms-/;
/**
* Camelcases a hyphenated CSS property name, for example:
*
* > camelizeStyleName('background-color')
* < "backgroundColor"
* > camelizeStyleName('-moz-transition')
* < "MozTransition"
* > camelizeStyleName('-ms-transition')
* < "msTransition"
*
* As Andi Smith suggests
* (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix
* is converted to lowercase `ms`.
*
* @param {string} string
* @return {string}
*/
function camelizeStyleName(string) {
return camelize(string.replace(msPattern, 'ms-'));
}
module.exports = camelizeStyleName;

View File

@@ -0,0 +1,27 @@
/**
* Copyright 2015-present Facebook. All Rights Reserved.
*
* @typechecks
*
*/
'use strict';
/**
* Returns a new Array containing all the element of the source array except
* `null` and `undefined` ones. This brings the benefit of strong typing over
* `Array.prototype.filter`.
*/
function compactArray(array) {
var result = [];
for (var i = 0; i < array.length; ++i) {
var elem = array[i];
if (elem != null) {
result.push(elem);
}
}
return result;
}
module.exports = compactArray;

View File

@@ -0,0 +1,28 @@
/**
* Copyright 2015-present Facebook. All Rights Reserved.
*
* @providesModule compactArray
* @typechecks
* @flow
*/
'use strict';
/**
* Returns a new Array containing all the element of the source array except
* `null` and `undefined` ones. This brings the benefit of strong typing over
* `Array.prototype.filter`.
*/
function compactArray<T>(array: Array<T | null | void>): Array<T> {
var result = [];
for (var i = 0; i < array.length; ++i) {
var elem = array[i];
if (elem != null) {
result.push(elem);
}
}
return result;
}
module.exports = compactArray;

View File

@@ -0,0 +1,33 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
var push = Array.prototype.push;
/**
* Concats an array of arrays into a single flat array.
*
* @param {array} array
* @return {array}
*/
function concatAllArray(array) {
var ret = [];
for (var ii = 0; ii < array.length; ii++) {
var value = array[ii];
if (Array.isArray(value)) {
push.apply(ret, value);
} else if (value != null) {
throw new TypeError('concatAllArray: All items in the array must be an array or null, ' + 'got "' + value + '" at index "' + ii + '" instead');
}
}
return ret;
}
module.exports = concatAllArray;

View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule concatAllArray
* @typechecks
*/
var push = Array.prototype.push;
/**
* Concats an array of arrays into a single flat array.
*
* @param {array} array
* @return {array}
*/
function concatAllArray(array) {
var ret = [];
for (var ii = 0; ii < array.length; ii++) {
var value = array[ii];
if (Array.isArray(value)) {
push.apply(ret, value);
} else if (value != null) {
throw new TypeError('concatAllArray: All items in the array must be an array or null, ' + 'got "' + value + '" at index "' + ii + '" instead');
}
}
return ret;
}
module.exports = concatAllArray;

View File

@@ -0,0 +1,37 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
var isTextNode = require('./isTextNode');
/*eslint-disable no-bitwise */
/**
* Checks if a given DOM node contains or is another DOM node.
*/
function containsNode(outerNode, innerNode) {
if (!outerNode || !innerNode) {
return false;
} else if (outerNode === innerNode) {
return true;
} else if (isTextNode(outerNode)) {
return false;
} else if (isTextNode(innerNode)) {
return containsNode(outerNode, innerNode.parentNode);
} else if ('contains' in outerNode) {
return outerNode.contains(innerNode);
} else if (outerNode.compareDocumentPosition) {
return !!(outerNode.compareDocumentPosition(innerNode) & 16);
} else {
return false;
}
}
module.exports = containsNode;

View File

@@ -0,0 +1,36 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule containsNode
* @flow
*/
const isTextNode = require('./isTextNode');
/*eslint-disable no-bitwise */
/**
* Checks if a given DOM node contains or is another DOM node.
*/
function containsNode(outerNode: ?Node, innerNode: ?Node): boolean {
if (!outerNode || !innerNode) {
return false;
} else if (outerNode === innerNode) {
return true;
} else if (isTextNode(outerNode)) {
return false;
} else if (isTextNode(innerNode)) {
return containsNode(outerNode, innerNode.parentNode);
} else if ('contains' in outerNode) {
return outerNode.contains(innerNode);
} else if (outerNode.compareDocumentPosition) {
return !!(outerNode.compareDocumentPosition(innerNode) & 16);
} else {
return false;
}
}
module.exports = containsNode;

View File

@@ -0,0 +1,51 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
'use strict';
var Set = require('./Set');
var emptyFunction = require('./emptyFunction');
/**
* Returns the count of distinct elements selected from an array.
*/
function countDistinct(iter, selector) {
selector = selector || emptyFunction.thatReturnsArgument;
var set = new Set();
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = iter[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var val = _step.value;
set.add(selector(val));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return set.size;
}
module.exports = countDistinct;

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule countDistinct
* @flow
*/
'use strict';
var Set = require('./Set');
var emptyFunction = require('./emptyFunction');
/**
* Returns the count of distinct elements selected from an array.
*/
function countDistinct<T1, T2>(iter: Iterable<T1>, selector: (item: T1) => T2): number {
selector = selector || emptyFunction.thatReturnsArgument;
var set = new Set();
for (var val of iter) {
set.add(selector(val));
}
return set.size;
}
module.exports = countDistinct;

View File

@@ -0,0 +1,27 @@
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
function crc32(str) {
/* jslint bitwise: true */
var crc = -1;
for (var i = 0, len = str.length; i < len; i++) {
crc = crc >>> 8 ^ table[(crc ^ str.charCodeAt(i)) & 0xFF];
}
return ~crc;
}
var table = [0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D];
if (global.Int32Array !== undefined) {
table = new Int32Array(table);
}
module.exports = crc32;

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule crc32
* @flow
*/
function crc32(str: string): number {
/* jslint bitwise: true */
var crc = -1;
for (var i = 0, len = str.length; i < len; i++) {
crc = crc >>> 8 ^ table[(crc ^ str.charCodeAt(i)) & 0xFF];
}
return ~crc;
}
var table = [0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D];
if (global.Int32Array !== undefined) {
table = new Int32Array(table);
}
module.exports = crc32;

View File

@@ -0,0 +1,124 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
var invariant = require('./invariant');
/**
* Convert array-like objects to arrays.
*
* This API assumes the caller knows the contents of the data type. For less
* well defined inputs use createArrayFromMixed.
*
* @param {object|function|filelist} obj
* @return {array}
*/
function toArray(obj) {
var length = obj.length;
// Some browsers builtin objects can report typeof 'function' (e.g. NodeList
// in old versions of Safari).
!(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Array-like object expected') : invariant(false) : void 0;
!(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object needs a length property') : invariant(false) : void 0;
!(length === 0 || length - 1 in obj) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object should have keys for indices') : invariant(false) : void 0;
!(typeof obj.callee !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object can\'t be `arguments`. Use rest params ' + '(function(...args) {}) or Array.from() instead.') : invariant(false) : void 0;
// Old IE doesn't give collections access to hasOwnProperty. Assume inputs
// without method will throw during the slice call and skip straight to the
// fallback.
if (obj.hasOwnProperty) {
try {
return Array.prototype.slice.call(obj);
} catch (e) {
// IE < 9 does not support Array#slice on collections objects
}
}
// Fall back to copying key by key. This assumes all keys have a value,
// so will not preserve sparsely populated inputs.
var ret = Array(length);
for (var ii = 0; ii < length; ii++) {
ret[ii] = obj[ii];
}
return ret;
}
/**
* Perform a heuristic test to determine if an object is "array-like".
*
* A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
* Joshu replied: "Mu."
*
* This function determines if its argument has "array nature": it returns
* true if the argument is an actual array, an `arguments' object, or an
* HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
*
* It will return false for other array-like objects like Filelist.
*
* @param {*} obj
* @return {boolean}
*/
function hasArrayNature(obj) {
return (
// not null/false
!!obj && (
// arrays are objects, NodeLists are functions in Safari
typeof obj == 'object' || typeof obj == 'function') &&
// quacks like an array
'length' in obj &&
// not window
!('setInterval' in obj) &&
// no DOM node should be considered an array-like
// a 'select' element has 'length' and 'item' properties on IE8
typeof obj.nodeType != 'number' && (
// a real array
Array.isArray(obj) ||
// arguments
'callee' in obj ||
// HTMLCollection/NodeList
'item' in obj)
);
}
/**
* Ensure that the argument is an array by wrapping it in an array if it is not.
* Creates a copy of the argument if it is already an array.
*
* This is mostly useful idiomatically:
*
* var createArrayFromMixed = require('createArrayFromMixed');
*
* function takesOneOrMoreThings(things) {
* things = createArrayFromMixed(things);
* ...
* }
*
* This allows you to treat `things' as an array, but accept scalars in the API.
*
* If you need to convert an array-like object, like `arguments`, into an array
* use toArray instead.
*
* @param {*} obj
* @return {array}
*/
function createArrayFromMixed(obj) {
if (!hasArrayNature(obj)) {
return [obj];
} else if (Array.isArray(obj)) {
return obj.slice();
} else {
return toArray(obj);
}
}
module.exports = createArrayFromMixed;

View File

@@ -0,0 +1,123 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule createArrayFromMixed
* @typechecks
*/
const invariant = require('./invariant');
/**
* Convert array-like objects to arrays.
*
* This API assumes the caller knows the contents of the data type. For less
* well defined inputs use createArrayFromMixed.
*
* @param {object|function|filelist} obj
* @return {array}
*/
function toArray(obj) {
const length = obj.length;
// Some browsers builtin objects can report typeof 'function' (e.g. NodeList
// in old versions of Safari).
invariant(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function'), 'toArray: Array-like object expected');
invariant(typeof length === 'number', 'toArray: Object needs a length property');
invariant(length === 0 || length - 1 in obj, 'toArray: Object should have keys for indices');
invariant(typeof obj.callee !== 'function', 'toArray: Object can\'t be `arguments`. Use rest params ' + '(function(...args) {}) or Array.from() instead.');
// Old IE doesn't give collections access to hasOwnProperty. Assume inputs
// without method will throw during the slice call and skip straight to the
// fallback.
if (obj.hasOwnProperty) {
try {
return Array.prototype.slice.call(obj);
} catch (e) {
// IE < 9 does not support Array#slice on collections objects
}
}
// Fall back to copying key by key. This assumes all keys have a value,
// so will not preserve sparsely populated inputs.
const ret = Array(length);
for (let ii = 0; ii < length; ii++) {
ret[ii] = obj[ii];
}
return ret;
}
/**
* Perform a heuristic test to determine if an object is "array-like".
*
* A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
* Joshu replied: "Mu."
*
* This function determines if its argument has "array nature": it returns
* true if the argument is an actual array, an `arguments' object, or an
* HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
*
* It will return false for other array-like objects like Filelist.
*
* @param {*} obj
* @return {boolean}
*/
function hasArrayNature(obj) {
return (
// not null/false
!!obj && (
// arrays are objects, NodeLists are functions in Safari
typeof obj == 'object' || typeof obj == 'function') &&
// quacks like an array
'length' in obj &&
// not window
!('setInterval' in obj) &&
// no DOM node should be considered an array-like
// a 'select' element has 'length' and 'item' properties on IE8
typeof obj.nodeType != 'number' && (
// a real array
Array.isArray(obj) ||
// arguments
'callee' in obj ||
// HTMLCollection/NodeList
'item' in obj)
);
}
/**
* Ensure that the argument is an array by wrapping it in an array if it is not.
* Creates a copy of the argument if it is already an array.
*
* This is mostly useful idiomatically:
*
* var createArrayFromMixed = require('createArrayFromMixed');
*
* function takesOneOrMoreThings(things) {
* things = createArrayFromMixed(things);
* ...
* }
*
* This allows you to treat `things' as an array, but accept scalars in the API.
*
* If you need to convert an array-like object, like `arguments`, into an array
* use toArray instead.
*
* @param {*} obj
* @return {array}
*/
function createArrayFromMixed(obj) {
if (!hasArrayNature(obj)) {
return [obj];
} else if (Array.isArray(obj)) {
return obj.slice();
} else {
return toArray(obj);
}
}
module.exports = createArrayFromMixed;

View File

@@ -0,0 +1,81 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @typechecks
*/
/*eslint-disable fb-www/unsafe-html*/
var ExecutionEnvironment = require('./ExecutionEnvironment');
var createArrayFromMixed = require('./createArrayFromMixed');
var getMarkupWrap = require('./getMarkupWrap');
var invariant = require('./invariant');
/**
* Dummy container used to render all markup.
*/
var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null;
/**
* Pattern used by `getNodeName`.
*/
var nodeNamePattern = /^\s*<(\w+)/;
/**
* Extracts the `nodeName` of the first element in a string of markup.
*
* @param {string} markup String of markup.
* @return {?string} Node name of the supplied markup.
*/
function getNodeName(markup) {
var nodeNameMatch = markup.match(nodeNamePattern);
return nodeNameMatch && nodeNameMatch[1].toLowerCase();
}
/**
* Creates an array containing the nodes rendered from the supplied markup. The
* optionally supplied `handleScript` function will be invoked once for each
* <script> element that is rendered. If no `handleScript` function is supplied,
* an exception is thrown if any <script> elements are rendered.
*
* @param {string} markup A string of valid HTML markup.
* @param {?function} handleScript Invoked once for each rendered <script>.
* @return {array<DOMElement|DOMTextNode>} An array of rendered nodes.
*/
function createNodesFromMarkup(markup, handleScript) {
var node = dummyNode;
!!!dummyNode ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createNodesFromMarkup dummy not initialized') : invariant(false) : void 0;
var nodeName = getNodeName(markup);
var wrap = nodeName && getMarkupWrap(nodeName);
if (wrap) {
node.innerHTML = wrap[1] + markup + wrap[2];
var wrapDepth = wrap[0];
while (wrapDepth--) {
node = node.lastChild;
}
} else {
node.innerHTML = markup;
}
var scripts = node.getElementsByTagName('script');
if (scripts.length) {
!handleScript ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createNodesFromMarkup(...): Unexpected <script> element rendered.') : invariant(false) : void 0;
createArrayFromMixed(scripts).forEach(handleScript);
}
var nodes = Array.from(node.childNodes);
while (node.lastChild) {
node.removeChild(node.lastChild);
}
return nodes;
}
module.exports = createNodesFromMarkup;

View File

@@ -0,0 +1,80 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule createNodesFromMarkup
* @typechecks
*/
/*eslint-disable fb-www/unsafe-html*/
const ExecutionEnvironment = require('./ExecutionEnvironment');
const createArrayFromMixed = require('./createArrayFromMixed');
const getMarkupWrap = require('./getMarkupWrap');
const invariant = require('./invariant');
/**
* Dummy container used to render all markup.
*/
const dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null;
/**
* Pattern used by `getNodeName`.
*/
const nodeNamePattern = /^\s*<(\w+)/;
/**
* Extracts the `nodeName` of the first element in a string of markup.
*
* @param {string} markup String of markup.
* @return {?string} Node name of the supplied markup.
*/
function getNodeName(markup) {
const nodeNameMatch = markup.match(nodeNamePattern);
return nodeNameMatch && nodeNameMatch[1].toLowerCase();
}
/**
* Creates an array containing the nodes rendered from the supplied markup. The
* optionally supplied `handleScript` function will be invoked once for each
* <script> element that is rendered. If no `handleScript` function is supplied,
* an exception is thrown if any <script> elements are rendered.
*
* @param {string} markup A string of valid HTML markup.
* @param {?function} handleScript Invoked once for each rendered <script>.
* @return {array<DOMElement|DOMTextNode>} An array of rendered nodes.
*/
function createNodesFromMarkup(markup, handleScript) {
let node = dummyNode;
invariant(!!dummyNode, 'createNodesFromMarkup dummy not initialized');
const nodeName = getNodeName(markup);
const wrap = nodeName && getMarkupWrap(nodeName);
if (wrap) {
node.innerHTML = wrap[1] + markup + wrap[2];
let wrapDepth = wrap[0];
while (wrapDepth--) {
node = node.lastChild;
}
} else {
node.innerHTML = markup;
}
const scripts = node.getElementsByTagName('script');
if (scripts.length) {
invariant(handleScript, 'createNodesFromMarkup(...): Unexpected <script> element rendered.');
createArrayFromMixed(scripts).forEach(handleScript);
}
const nodes = Array.from(node.childNodes);
while (node.lastChild) {
node.removeChild(node.lastChild);
}
return nodes;
}
module.exports = createNodesFromMarkup;

View File

@@ -0,0 +1,39 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/**
* This function is used to mark string literals representing CSS class names
* so that they can be transformed statically. This allows for modularization
* and minification of CSS class names.
*
* In static_upstream, this function is actually implemented, but it should
* eventually be replaced with something more descriptive, and the transform
* that is used in the main stack should be ported for use elsewhere.
*
* @param string|object className to modularize, or an object of key/values.
* In the object case, the values are conditions that
* determine if the className keys should be included.
* @param [string ...] Variable list of classNames in the string case.
* @return string Renderable space-separated CSS className.
*/
function cx(classNames) {
if (typeof classNames == 'object') {
return Object.keys(classNames).filter(function (className) {
return classNames[className];
}).map(replace).join(' ');
}
return Array.prototype.map.call(arguments, replace).join(' ');
}
function replace(str) {
return str.replace(/\//g, '-');
}
module.exports = cx;

View File

@@ -0,0 +1,36 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule cx
*/
/**
* This function is used to mark string literals representing CSS class names
* so that they can be transformed statically. This allows for modularization
* and minification of CSS class names.
*
* In static_upstream, this function is actually implemented, but it should
* eventually be replaced with something more descriptive, and the transform
* that is used in the main stack should be ported for use elsewhere.
*
* @param string|object className to modularize, or an object of key/values.
* In the object case, the values are conditions that
* determine if the className keys should be included.
* @param [string ...] Variable list of classNames in the string case.
* @return string Renderable space-separated CSS className.
*/
function cx(classNames) {
if (typeof classNames == 'object') {
return Object.keys(classNames).filter(className => classNames[className]).map(replace).join(' ');
}
return Array.prototype.map.call(arguments, replace).join(' ');
}
function replace(str) {
return str.replace(/\//g, '-');
}
module.exports = cx;

View File

@@ -0,0 +1,22 @@
'use strict';
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
var Set = require('./Set');
/**
* Returns the distinct elements of an iterable. The result is an array whose
* elements are ordered by first occurrence.
*/
function distinctArray(xs) {
return Array.from(new Set(xs).values());
}
module.exports = distinctArray;

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule distinctArray
* @flow
*/
var Set = require('./Set');
/**
* Returns the distinct elements of an iterable. The result is an array whose
* elements are ordered by first occurrence.
*/
function distinctArray<T>(xs: Iterable<T>): Array<T> {
return Array.from(new Set(xs).values());
}
module.exports = distinctArray;

View File

@@ -0,0 +1,36 @@
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;

View File

@@ -0,0 +1,35 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule emptyFunction
* @flow
*/
function makeEmptyFunction<T>(arg: T): (...args: Array<any>) => T {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
const emptyFunction: (...args: Array<any>) => void = function () {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
var emptyObject = {};
if (process.env.NODE_ENV !== 'production') {
Object.freeze(emptyObject);
}
module.exports = emptyObject;

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule emptyObject
*/
'use strict';
const emptyObject = {};
if (__DEV__) {
Object.freeze(emptyObject);
}
module.exports = emptyObject;

View File

@@ -0,0 +1,305 @@
'use strict';
var _assign = require('object-assign');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
var KIND_KEYS = 'keys';
var KIND_VALUES = 'values';
var KIND_ENTRIES = 'entries';
/**
* Specific Array iterators.
*/
var ArrayIterators = function () {
var hasNative = hasNativeIterator(Array);
var ArrayIterator = void 0;
if (!hasNative) {
ArrayIterator = function () {
// 22.1.5.1 CreateArrayIterator Abstract Operation
function ArrayIterator(array, kind) {
_classCallCheck(this, ArrayIterator);
this._iteratedObject = array;
this._kind = kind;
this._nextIndex = 0;
}
// 22.1.5.2.1 %ArrayIteratorPrototype%.next()
ArrayIterator.prototype.next = function next() {
if (this._iteratedObject == null) {
return { value: undefined, done: true };
}
var array = this._iteratedObject;
var len = this._iteratedObject.length;
var index = this._nextIndex;
var kind = this._kind;
if (index >= len) {
this._iteratedObject = undefined;
return { value: undefined, done: true };
}
this._nextIndex = index + 1;
if (kind === KIND_KEYS) {
return { value: index, done: false };
} else if (kind === KIND_VALUES) {
return { value: array[index], done: false };
} else if (kind === KIND_ENTRIES) {
return { value: [index, array[index]], done: false };
}
};
// 22.1.5.2.2 %ArrayIteratorPrototype%[@@iterator]()
ArrayIterator.prototype[Symbol.iterator] = function () {
return this;
};
return ArrayIterator;
}();
}
return {
keys: hasNative ? function (array) {
return array.keys();
} : function (array) {
return new ArrayIterator(array, KIND_KEYS);
},
values: hasNative ? function (array) {
return array.values();
} : function (array) {
return new ArrayIterator(array, KIND_VALUES);
},
entries: hasNative ? function (array) {
return array.entries();
} : function (array) {
return new ArrayIterator(array, KIND_ENTRIES);
}
};
}();
// -----------------------------------------------------------------
/**
* Specific String iterators.
*/
var StringIterators = function () {
var hasNative = hasNativeIterator(String);
var StringIterator = void 0;
if (!hasNative) {
StringIterator = function () {
// 21.1.5.1 CreateStringIterator Abstract Operation
function StringIterator(string) {
_classCallCheck(this, StringIterator);
this._iteratedString = string;
this._nextIndex = 0;
}
// 21.1.5.2.1 %StringIteratorPrototype%.next()
StringIterator.prototype.next = function next() {
if (this._iteratedString == null) {
return { value: undefined, done: true };
}
var index = this._nextIndex;
var s = this._iteratedString;
var len = s.length;
if (index >= len) {
this._iteratedString = undefined;
return { value: undefined, done: true };
}
var ret = void 0;
var first = s.charCodeAt(index);
if (first < 0xD800 || first > 0xDBFF || index + 1 === len) {
ret = s[index];
} else {
var second = s.charCodeAt(index + 1);
if (second < 0xDC00 || second > 0xDFFF) {
ret = s[index];
} else {
ret = s[index] + s[index + 1];
}
}
this._nextIndex = index + ret.length;
return { value: ret, done: false };
};
// 21.1.5.2.2 %StringIteratorPrototype%[@@iterator]()
StringIterator.prototype[Symbol.iterator] = function () {
return this;
};
return StringIterator;
}();
}
return {
keys: function keys() {
throw TypeError('Strings default iterator doesn\'t implement keys.');
},
values: hasNative ? function (string) {
return string[Symbol.iterator]();
} : function (string) {
return new StringIterator(string);
},
entries: function entries() {
throw TypeError('Strings default iterator doesn\'t implement entries.');
}
};
}();
function hasNativeIterator(classObject) {
return typeof classObject.prototype[Symbol.iterator] === 'function' && typeof classObject.prototype.values === 'function' && typeof classObject.prototype.keys === 'function' && typeof classObject.prototype.entries === 'function';
}
// -----------------------------------------------------------------
/**
* Generic object iterator.
*/
var ObjectIterator = function () {
function ObjectIterator(object, kind) {
_classCallCheck(this, ObjectIterator);
this._iteratedObject = object;
this._kind = kind;
this._keys = Object.keys(object);
this._nextIndex = 0;
}
ObjectIterator.prototype.next = function next() {
var len = this._keys.length;
var index = this._nextIndex;
var kind = this._kind;
var key = this._keys[index];
if (index >= len) {
this._iteratedObject = undefined;
return { value: undefined, done: true };
}
this._nextIndex = index + 1;
if (kind === KIND_KEYS) {
return { value: key, done: false };
} else if (kind === KIND_VALUES) {
return { value: this._iteratedObject[key], done: false };
} else if (kind === KIND_ENTRIES) {
return { value: [key, this._iteratedObject[key]], done: false };
}
};
ObjectIterator.prototype[Symbol.iterator] = function () {
return this;
};
return ObjectIterator;
}();
/**
* Generic object iterator, iterates over all own enumerable
* properties. Used only if if no specific iterator is available,
* and object don't implement iterator protocol.
*/
var GenericIterators = {
keys: function keys(object) {
return new ObjectIterator(object, KIND_KEYS);
},
values: function values(object) {
return new ObjectIterator(object, KIND_VALUES);
},
entries: function entries(object) {
return new ObjectIterator(object, KIND_ENTRIES);
}
};
// -----------------------------------------------------------------
/**
* Main iterator function. Returns default iterator based
* on the class of an instance.
*/
function enumerate(object, kind) {
// First check specific iterators.
if (typeof object === 'string') {
return StringIterators[kind || KIND_VALUES](object);
} else if (Array.isArray(object)) {
return ArrayIterators[kind || KIND_VALUES](object);
// Then see if an object implements own.
} else if (object[Symbol.iterator]) {
return object[Symbol.iterator]();
// And fallback to generic with entries.
} else {
return GenericIterators[kind || KIND_ENTRIES](object);
}
}
_assign(enumerate, {
/**
* Export constants
*/
KIND_KEYS: KIND_KEYS,
KIND_VALUES: KIND_VALUES,
KIND_ENTRIES: KIND_ENTRIES,
/**
* Convenient explicit iterators for special kinds.
*/
keys: function keys(object) {
return enumerate(object, KIND_KEYS);
},
values: function values(object) {
return enumerate(object, KIND_VALUES);
},
entries: function entries(object) {
return enumerate(object, KIND_ENTRIES);
},
generic: GenericIterators.entries
});
module.exports = enumerate;

View File

@@ -0,0 +1,263 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule enumerate
*
*/
const KIND_KEYS = 'keys';
const KIND_VALUES = 'values';
const KIND_ENTRIES = 'entries';
/**
* Specific Array iterators.
*/
const ArrayIterators = function () {
let hasNative = hasNativeIterator(Array);
let ArrayIterator;
if (!hasNative) {
ArrayIterator = class ArrayIterator {
// 22.1.5.1 CreateArrayIterator Abstract Operation
constructor(array, kind) {
this._iteratedObject = array;
this._kind = kind;
this._nextIndex = 0;
}
// 22.1.5.2.1 %ArrayIteratorPrototype%.next()
next() {
if (this._iteratedObject == null) {
return { value: undefined, done: true };
}
let array = this._iteratedObject;
let len = this._iteratedObject.length;
let index = this._nextIndex;
let kind = this._kind;
if (index >= len) {
this._iteratedObject = undefined;
return { value: undefined, done: true };
}
this._nextIndex = index + 1;
if (kind === KIND_KEYS) {
return { value: index, done: false };
} else if (kind === KIND_VALUES) {
return { value: array[index], done: false };
} else if (kind === KIND_ENTRIES) {
return { value: [index, array[index]], done: false };
}
}
// 22.1.5.2.2 %ArrayIteratorPrototype%[@@iterator]()
[Symbol.iterator]() {
return this;
}
};
}
return {
keys: hasNative ? array => array.keys() : array => new ArrayIterator(array, KIND_KEYS),
values: hasNative ? array => array.values() : array => new ArrayIterator(array, KIND_VALUES),
entries: hasNative ? array => array.entries() : array => new ArrayIterator(array, KIND_ENTRIES)
};
}();
// -----------------------------------------------------------------
/**
* Specific String iterators.
*/
const StringIterators = function () {
let hasNative = hasNativeIterator(String);
let StringIterator;
if (!hasNative) {
StringIterator = class StringIterator {
// 21.1.5.1 CreateStringIterator Abstract Operation
constructor(string) {
this._iteratedString = string;
this._nextIndex = 0;
}
// 21.1.5.2.1 %StringIteratorPrototype%.next()
next() {
if (this._iteratedString == null) {
return { value: undefined, done: true };
}
let index = this._nextIndex;
let s = this._iteratedString;
let len = s.length;
if (index >= len) {
this._iteratedString = undefined;
return { value: undefined, done: true };
}
let ret;
let first = s.charCodeAt(index);
if (first < 0xD800 || first > 0xDBFF || index + 1 === len) {
ret = s[index];
} else {
let second = s.charCodeAt(index + 1);
if (second < 0xDC00 || second > 0xDFFF) {
ret = s[index];
} else {
ret = s[index] + s[index + 1];
}
}
this._nextIndex = index + ret.length;
return { value: ret, done: false };
}
// 21.1.5.2.2 %StringIteratorPrototype%[@@iterator]()
[Symbol.iterator]() {
return this;
}
};
}
return {
keys() {
throw TypeError(`Strings default iterator doesn't implement keys.`);
},
values: hasNative ? string => string[Symbol.iterator]() : string => new StringIterator(string),
entries() {
throw TypeError(`Strings default iterator doesn't implement entries.`);
}
};
}();
function hasNativeIterator(classObject) {
return typeof classObject.prototype[Symbol.iterator] === 'function' && typeof classObject.prototype.values === 'function' && typeof classObject.prototype.keys === 'function' && typeof classObject.prototype.entries === 'function';
}
// -----------------------------------------------------------------
/**
* Generic object iterator.
*/
class ObjectIterator {
constructor(object, kind) {
this._iteratedObject = object;
this._kind = kind;
this._keys = Object.keys(object);
this._nextIndex = 0;
}
next() {
let len = this._keys.length;
let index = this._nextIndex;
let kind = this._kind;
let key = this._keys[index];
if (index >= len) {
this._iteratedObject = undefined;
return { value: undefined, done: true };
}
this._nextIndex = index + 1;
if (kind === KIND_KEYS) {
return { value: key, done: false };
} else if (kind === KIND_VALUES) {
return { value: this._iteratedObject[key], done: false };
} else if (kind === KIND_ENTRIES) {
return { value: [key, this._iteratedObject[key]], done: false };
}
}
[Symbol.iterator]() {
return this;
}
}
/**
* Generic object iterator, iterates over all own enumerable
* properties. Used only if if no specific iterator is available,
* and object don't implement iterator protocol.
*/
const GenericIterators = {
keys(object) {
return new ObjectIterator(object, KIND_KEYS);
},
values(object) {
return new ObjectIterator(object, KIND_VALUES);
},
entries(object) {
return new ObjectIterator(object, KIND_ENTRIES);
}
};
// -----------------------------------------------------------------
/**
* Main iterator function. Returns default iterator based
* on the class of an instance.
*/
function enumerate(object, kind) {
// First check specific iterators.
if (typeof object === 'string') {
return StringIterators[kind || KIND_VALUES](object);
} else if (Array.isArray(object)) {
return ArrayIterators[kind || KIND_VALUES](object);
// Then see if an object implements own.
} else if (object[Symbol.iterator]) {
return object[Symbol.iterator]();
// And fallback to generic with entries.
} else {
return GenericIterators[kind || KIND_ENTRIES](object);
}
}
Object.assign(enumerate, {
/**
* Export constants
*/
KIND_KEYS,
KIND_VALUES,
KIND_ENTRIES,
/**
* Convenient explicit iterators for special kinds.
*/
keys(object) {
return enumerate(object, KIND_KEYS);
},
values(object) {
return enumerate(object, KIND_VALUES);
},
entries(object) {
return enumerate(object, KIND_ENTRIES);
},
generic: GenericIterators.entries
});
module.exports = enumerate;

View File

@@ -0,0 +1,64 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
'use strict';
var enumerate = require('./enumerate');
/**
* Checks if two iterables are equal. A custom areEqual function may be provided
* as an optional third argument.
*/
function equalsIterable(one, two, areEqual) {
if (one === two) {
return true;
}
// We might be able to short circuit by using the size or length fields.
var oneSize = maybeGetSize(one);
var twoSize = maybeGetSize(two);
if (oneSize != null && twoSize != null && oneSize !== twoSize) {
return false;
}
// Otherwise use the iterators to check equality. Here we cannot use for-of
// because we need to advance the iterators at the same time.
var oneIterator = enumerate(one);
var oneItem = oneIterator.next();
var twoIterator = enumerate(two);
var twoItem = twoIterator.next();
var safeAreEqual = areEqual || referenceEquality;
while (!(oneItem.done || twoItem.done)) {
if (!safeAreEqual(oneItem.value, twoItem.value)) {
return false;
}
oneItem = oneIterator.next();
twoItem = twoIterator.next();
}
return oneItem.done === twoItem.done;
}
function maybeGetSize(o) {
if (o == null) {
return null;
}
if (typeof o.size === 'number') {
return o.size;
}
if (typeof o.length === 'number') {
return o.length;
}
return null;
}
function referenceEquality(one, two) {
return one === two;
}
module.exports = equalsIterable;

View File

@@ -0,0 +1,65 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule equalsIterable
* @flow
*/
'use strict';
const enumerate = require('./enumerate');
/**
* Checks if two iterables are equal. A custom areEqual function may be provided
* as an optional third argument.
*/
function equalsIterable<T>(one: Iterable<T>, two: Iterable<T>, areEqual?: ?(one: T, two: T) => boolean): boolean {
if (one === two) {
return true;
}
// We might be able to short circuit by using the size or length fields.
var oneSize = maybeGetSize(one);
var twoSize = maybeGetSize(two);
if (oneSize != null && twoSize != null && oneSize !== twoSize) {
return false;
}
// Otherwise use the iterators to check equality. Here we cannot use for-of
// because we need to advance the iterators at the same time.
var oneIterator = enumerate(one);
var oneItem = oneIterator.next();
var twoIterator = enumerate(two);
var twoItem = twoIterator.next();
var safeAreEqual = areEqual || referenceEquality;
while (!(oneItem.done || twoItem.done)) {
if (!safeAreEqual(oneItem.value, twoItem.value)) {
return false;
}
oneItem = oneIterator.next();
twoItem = twoIterator.next();
}
return oneItem.done === twoItem.done;
}
function maybeGetSize(o: any): ?number {
if (o == null) {
return null;
}
if (typeof o.size === 'number') {
return o.size;
}
if (typeof o.length === 'number') {
return o.length;
}
return null;
}
function referenceEquality<T>(one: T, two: T): boolean {
return one === two;
}
module.exports = equalsIterable;

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @typechecks
*/
'use strict';
var everySet = require('./everySet');
/**
* Checks if two sets are equal
*/
function equalsSet(one, two) {
if (one.size !== two.size) {
return false;
}
return everySet(one, function (value) {
return two.has(value);
});
}
module.exports = equalsSet;

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule equalsSet
* @flow
* @typechecks
*/
'use strict';
import type Set from './Set';
var everySet = require('./everySet');
/**
* Checks if two sets are equal
*/
function equalsSet<T>(one: Set<T>, two: Set<T>): boolean {
if (one.size !== two.size) {
return false;
}
return everySet(one, value => two.has(value));
}
module.exports = equalsSet;

Some files were not shown because too many files have changed in this diff Show More