1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | Object.defineProperty(exports, "__esModule", { value: true });
|
15 | var core_1 = require("@aws-amplify/core");
|
16 |
|
17 |
|
18 |
|
19 | exports.defaultConfig = {
|
20 | keyPrefix: 'aws-amplify-cache',
|
21 | capacityInBytes: 1048576,
|
22 | itemMaxSize: 210000,
|
23 | defaultTTL: 259200000,
|
24 | defaultPriority: 5,
|
25 | warningThreshold: 0.8,
|
26 |
|
27 |
|
28 | storage: new core_1.StorageHelper().getStorage(),
|
29 | };
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function getByteLength(str) {
|
35 | var ret = 0;
|
36 | ret = str.length;
|
37 | for (var i = str.length; i >= 0; i -= 1) {
|
38 | var charCode = str.charCodeAt(i);
|
39 | if (charCode > 0x7f && charCode <= 0x7ff) {
|
40 | ret += 1;
|
41 | }
|
42 | else if (charCode > 0x7ff && charCode <= 0xffff) {
|
43 | ret += 2;
|
44 | }
|
45 |
|
46 | if (charCode >= 0xdc00 && charCode <= 0xdfff) {
|
47 | i -= 1;
|
48 | }
|
49 | }
|
50 | return ret;
|
51 | }
|
52 | exports.getByteLength = getByteLength;
|
53 |
|
54 |
|
55 |
|
56 | function getCurrTime() {
|
57 | var currTime = new Date();
|
58 | return currTime.getTime();
|
59 | }
|
60 | exports.getCurrTime = getCurrTime;
|
61 |
|
62 |
|
63 |
|
64 | function isInteger(value) {
|
65 | if (Number.isInteger) {
|
66 | return Number.isInteger(value);
|
67 | }
|
68 | return _isInteger(value);
|
69 | }
|
70 | exports.isInteger = isInteger;
|
71 | function _isInteger(value) {
|
72 | return (typeof value === 'number' && isFinite(value) && Math.floor(value) === value);
|
73 | }
|
74 |
|
75 |
|
76 |
|
77 | var store = {};
|
78 | var CacheObject = (function () {
|
79 | function CacheObject() {
|
80 | }
|
81 | CacheObject.clear = function () {
|
82 | store = {};
|
83 | };
|
84 | CacheObject.getItem = function (key) {
|
85 | return store[key] || null;
|
86 | };
|
87 | CacheObject.setItem = function (key, value) {
|
88 | store[key] = value;
|
89 | };
|
90 | CacheObject.removeItem = function (key) {
|
91 | delete store[key];
|
92 | };
|
93 | return CacheObject;
|
94 | }());
|
95 | exports.CacheObject = CacheObject;
|
96 |
|
\ | No newline at end of file |