diff --git a/src/util/getOwnObjectValues.js b/src/util/getOwnObjectValues.js new file mode 100644 index 0000000000..aa6ef555fb --- /dev/null +++ b/src/util/getOwnObjectValues.js @@ -0,0 +1,26 @@ +/** + * Copyright 2004-present Facebook. All Rights Reserved. + * + * @flow strict + * @typechecks + * @format + */ + +/** + * Retrieve an object's own values as an array. If you want the values in the + * protoype chain, too, use getObjectValuesIncludingPrototype. + * + * If you are looking for a function that creates an Array instance based + * on an "Array-like" object, use createArrayFrom instead. + * + * @param {object} obj An object. + * @return {array} The object's values. + */ +function getOwnObjectValues(obj: { + +[key: string]: TValue, + ..., +}): Array { + return Object.keys(obj).map(key => obj[key]); +} + +module.exports = getOwnObjectValues; diff --git a/src/util/uuid.js b/src/util/uuid.js new file mode 100644 index 0000000000..942cacd299 --- /dev/null +++ b/src/util/uuid.js @@ -0,0 +1,23 @@ +/** + * Copyright 2004-present Facebook. All Rights Reserved. + * + * @typechecks + * @flow strict + * @format + */ + +/*eslint-disable no-bitwise */ + +/** + * Based on the rfc4122-compliant solution posted at + * http://stackoverflow.com/questions/105034 + */ +function uuid(): string { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { + const r = (Math.random() * 16) | 0; + const v = c == 'x' ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); +} + +module.exports = uuid;