@react-native-firebase/common
Advanced tools
Comparing version 6.0.0-alpha.22 to 6.0.0-alpha.23
@@ -20,3 +20,3 @@ /* eslint-disable */ | ||
import binaryToBase64 from 'react-native/Libraries/Utilities/binaryToBase64'; | ||
import promiseDefer from './promiseDefer'; | ||
import { promiseDefer } from './promise'; | ||
@@ -23,0 +23,0 @@ const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; |
@@ -21,6 +21,7 @@ /* | ||
export * from './id'; | ||
export * from './path'; | ||
export * from './validate'; | ||
export * from './promise'; | ||
export Base64 from './Base64'; | ||
export promiseDefer from './promiseDefer'; | ||
export ReferenceBase from './ReferenceBase'; | ||
@@ -78,1 +79,17 @@ | ||
export const isAndroid = Platform.OS === 'android'; | ||
export function tryJSONParse(string) { | ||
try { | ||
return string && JSON.parse(string); | ||
} catch (jsonError) { | ||
return string; | ||
} | ||
} | ||
export function tryJSONStringify(data: mixed): string | null { | ||
try { | ||
return JSON.stringify(data); | ||
} catch (jsonError) { | ||
return null; | ||
} | ||
} |
@@ -38,6 +38,3 @@ /* | ||
export function pathChild(path, childPath) { | ||
const canonicalChildPath = childPath | ||
.split('/') | ||
.filter($ => $.length > 0) | ||
.join('/'); | ||
const canonicalChildPath = pathPieces(childPath).join('/'); | ||
@@ -62,1 +59,57 @@ if (path.length === 0) { | ||
} | ||
/** | ||
* Returns all none empty pieces of the path | ||
* @param path | ||
* @returns {*} | ||
*/ | ||
export function pathPieces(path) { | ||
return path.split('/').filter($ => $.length > 0); | ||
} | ||
/** | ||
* Returns whether a given path is empty | ||
* @param path | ||
* @returns {boolean} | ||
*/ | ||
export function pathIsEmpty(path) { | ||
return !pathPieces(path).length; | ||
} | ||
/** | ||
* Converts a given path to a URL encoded string | ||
* @param path | ||
* @returns {string|string} | ||
*/ | ||
export function pathToUrlEncodedString(path) { | ||
const pieces = pathPieces(path); | ||
let pathString = ''; | ||
for (let i = 0; i < pieces.length; i++) { | ||
pathString += `/${encodeURIComponent(String(pieces[i]))}`; | ||
} | ||
return pathString || '/'; | ||
} | ||
// eslint-disable-next-line no-control-regex | ||
export const INVALID_PATH_REGEX = /[[\].#$\u0000-\u001F\u007F]/; | ||
/** | ||
* Ensures a given path is a valid Firebase path | ||
* @param path | ||
* @returns {boolean} | ||
*/ | ||
export function isValidPath(path) { | ||
return typeof path === 'string' && path.length !== 0 && !INVALID_PATH_REGEX.test(path); | ||
} | ||
// eslint-disable-next-line no-control-regex,no-useless-escape | ||
export const INVALID_KEY_REGEX = /[\[\].#$\/\u0000-\u001F\u007F]/; | ||
/** | ||
* Ensures a given key is a valid Firebase key | ||
* @param key | ||
* @returns {boolean} | ||
*/ | ||
export function isValidKey(key) { | ||
return typeof key === 'string' && key.length !== 0 && !INVALID_KEY_REGEX.test(path); | ||
} |
{ | ||
"name": "@react-native-firebase/common", | ||
"version": "6.0.0-alpha.22", | ||
"version": "6.0.0-alpha.23", | ||
"author": "Invertase <oss@invertase.io> (http://invertase.io)", | ||
@@ -18,3 +18,3 @@ "description": "React Native Firebase internal common utilities & helpers.", | ||
], | ||
"gitHead": "68ddde98fe4e7135ebd8936bd671117d86ba9a5a", | ||
"gitHead": "1f2bd61ae34209638f5fccba99934cd546af9ee9", | ||
"publishConfig": { | ||
@@ -21,0 +21,0 @@ "access": "public" |
21594
12
600