-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (68 loc) · 2.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
const react_native_sensitive_info_1 = __importDefault(require("react-native-sensitive-info"));
function default_1(options = {}) {
const extractKeys = react_native_1.Platform.select({
android: Object.keys,
ios: (items) => items[0].map((item) => item.key)
});
function noop() {
return null;
}
return {
async getItem(key, callback = noop) {
try {
let result = await react_native_sensitive_info_1.default.getItem(key, options);
if (typeof result === 'undefined') {
result = null;
}
callback(null, result);
return result;
}
catch (error) {
callback(error);
throw error;
}
},
async setItem(key, value, callback = noop) {
try {
await react_native_sensitive_info_1.default.setItem(key, value, options);
callback(null);
}
catch (error) {
callback(error);
throw error;
}
},
async removeItem(key, callback = noop) {
try {
await react_native_sensitive_info_1.default.deleteItem(key, options);
callback(null);
}
catch (error) {
callback(error);
throw error;
}
},
async getAllKeys(callback = noop) {
try {
const values = await react_native_sensitive_info_1.default.getAllItems(options);
if (typeof extractKeys === 'undefined') {
throw new Error('Platform not supported');
}
const result = extractKeys(values);
callback(null, result);
return result;
}
catch (error) {
callback(error);
throw error;
}
}
};
}
exports.default = default_1;