• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 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 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
16const fs = require('fs');
17
18module.exports = { parseJson, readJson };
19
20function parseJson(jsonPath) {
21    try {
22        const fileData = fs.readFileSync(jsonPath, 'utf-8');
23        if (fileData === "") {
24            return 3;
25        }
26        return JSON.parse(fileData);
27    } catch (error) {
28        throw error;
29    }
30}
31
32function readJson(filePaths) {
33    let arr = [];
34    for (let i = 0; i < filePaths.length; i++) {
35        if (filePaths[i].includes('.json')) {
36            const jsonData = parseJson(filePaths[i]);
37            arr.push(jsonData);
38        }
39    }
40    return arr;
41}