@react-native-ohos/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
35 lines (34 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInitialValue = exports.getDataType = void 0;
const constants_1 = require("./constants");
const getDataType = (value) => {
if (value === null || value === undefined)
return null;
let type = Array.isArray(value) ? 'array' : typeof value;
return type;
};
exports.getDataType = getDataType;
const getInitialValue = (key, storage, initialValueType) => () => {
if (!(storage === null || storage === void 0 ? void 0 : storage.indexer)) {
return null;
}
let indexer = storage.indexer;
if (indexer.hasKey(key)) {
for (let i = 0; i < constants_1.types.length; i++) {
let type = constants_1.types[i];
//@ts-ignore
if (indexer[constants_1.methods[type].indexer].hasKey(key)) {
if (initialValueType === 'value') {
//@ts-ignore
return storage[constants_1.methods[type]['get']](key);
}
if (initialValueType === 'type') {
return type;
}
}
}
}
return null;
};
exports.getInitialValue = getInitialValue;