[firestore][js] First pass of javascript implementation

This commit is contained in:
Chris Bianca
2017-09-26 14:57:25 +01:00
parent 261edf7a83
commit dfd9080281
11 changed files with 946 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import { Platform } from 'react-native';
// modeled after base64 web-safe chars, but ordered by ASCII
const PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
const AUTO_ID_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const hasOwnProperty = Object.hasOwnProperty;
const DEFAULT_CHUNK_SIZE = 50;
@@ -373,3 +374,16 @@ export function promiseOrCallback(promise: Promise, optionalCallback?: Function)
return Promise.reject(error);
});
}
/**
* Generate a firestore auto id for use with collection/document .add()
* @return {string}
*/
export function firestoreAutoId(): string {
let autoId = '';
for (let i = 0; i < 20; i++) {
autoId += AUTO_ID_CHARS.charAt(Math.floor(Math.random() * AUTO_ID_CHARS.length));
}
return autoId;
}