1b0b2a9adSopenharmony_ci/* 2b0b2a9adSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3b0b2a9adSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4b0b2a9adSopenharmony_ci * you may not use this file except in compliance with the License. 5b0b2a9adSopenharmony_ci * You may obtain a copy of the License at 6b0b2a9adSopenharmony_ci * 7b0b2a9adSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8b0b2a9adSopenharmony_ci * 9b0b2a9adSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10b0b2a9adSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11b0b2a9adSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12b0b2a9adSopenharmony_ci * See the License for the specific language governing permissions and 13b0b2a9adSopenharmony_ci * limitations under the License. 14b0b2a9adSopenharmony_ci */ 15b0b2a9adSopenharmony_ci 16b0b2a9adSopenharmony_ciconst LARGE_SCREEN_GRID_SUM: number = 12; 17b0b2a9adSopenharmony_ciconst SMALL_SCREEN_GRID_SUM: number = 8; 18b0b2a9adSopenharmony_ciconst VP2PX_SUM_IN_LARGE_SCREEN: number = 2; 19b0b2a9adSopenharmony_ci 20b0b2a9adSopenharmony_ciclass Utils { 21b0b2a9adSopenharmony_ci isValid(item: unknown): boolean { 22b0b2a9adSopenharmony_ci return item !== null && item !== undefined; 23b0b2a9adSopenharmony_ci } 24b0b2a9adSopenharmony_ci 25b0b2a9adSopenharmony_ci checkObjPropertyValid<T>(obj: T, tree: string): boolean { 26b0b2a9adSopenharmony_ci if (!this.isValid(obj) || !this.isValid(tree)) { 27b0b2a9adSopenharmony_ci return false; 28b0b2a9adSopenharmony_ci } 29b0b2a9adSopenharmony_ci 30b0b2a9adSopenharmony_ci let arr = tree.split('.'); 31b0b2a9adSopenharmony_ci let tempObj = obj; 32b0b2a9adSopenharmony_ci for (let i = 0; i < arr.length; i++) { 33b0b2a9adSopenharmony_ci if (!this.isValid(tempObj[arr[i]])) { 34b0b2a9adSopenharmony_ci return false; 35b0b2a9adSopenharmony_ci } else { 36b0b2a9adSopenharmony_ci tempObj = tempObj[arr[i]]; 37b0b2a9adSopenharmony_ci } 38b0b2a9adSopenharmony_ci } 39b0b2a9adSopenharmony_ci return true; 40b0b2a9adSopenharmony_ci } 41b0b2a9adSopenharmony_ci 42b0b2a9adSopenharmony_ci isLargeDevice(): number { 43b0b2a9adSopenharmony_ci return vp2px(1) === VP2PX_SUM_IN_LARGE_SCREEN ? LARGE_SCREEN_GRID_SUM : SMALL_SCREEN_GRID_SUM; 44b0b2a9adSopenharmony_ci } 45b0b2a9adSopenharmony_ci} 46b0b2a9adSopenharmony_ci 47b0b2a9adSopenharmony_ciexport default new Utils();