kutaisan-react-native-mmkv-storage
Version:
This library aims to provide a fast & reliable solution for you data storage needs in react-native apps. It uses [MMKV](https://github.com/Tencent/MMKV) by Tencent under the hood on Android and iOS both that is used by their WeChat app(more than 1 Billion
31 lines (28 loc) • 750 B
JavaScript
import {types,methods} from "./constants";
export const getDataType = (value) => {
if (!value) return null;
let type = Array.isArray(value) ? "array" : typeof value;
return type;
};
export const getInitialValue =
({ key,storage,kindValue }) =>
() => {
if (!storage?.indexer) {
return null;
}
let indexer = storage.indexer;
if (indexer.hasKey(key)) {
for (let i = 0; i < types.length; i++) {
let type = types[i];
if (indexer[methods[type].indexer].hasKey(key)) {
if (kindValue === "value") {
return storage[methods[type]["get"]](key);
}
if (kindValue === "valueType") {
return type;
}
}
}
}
return null;
};