1/** 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file: data storage 18 */ 19import storage from '@ohos.data.storage'; 20import ImagePathConst from '../constant/ImagePathConst'; 21 22const storageObj = storage.getStorageSync(ImagePathConst.PHONE_NUMBER); 23 24export default class Storages { 25 /** 26 * set sync storage 27 * 28 * @param { string } key 29 * 30 * @param { string | number | boolean } value 31 */ 32 public setSyncStorage(key, value) { 33 if (typeof value !== 'string') { 34 value = JSON.stringify(value); 35 } 36 storageObj.putSync(key, value); 37 storageObj.flushSync(); 38 } 39 40 /** 41 * get sync storage 42 * 43 * @param { string } key 44 */ 45 public getSyncStorage = (key) => storageObj.getSync(key, ''); 46 47 /** 48 * get async storage 49 * 50 * @param { string } key 51 */ 52 public getAsyncStorage = (key) => storageObj.get(key, ''); 53 54 /** 55 * has sync storage 56 * 57 * @param { string } key 58 */ 59 public hasSyncStorage = (key) => storageObj.hasSync(key); 60}