• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 #ifndef FOUNDATION_ACE_INTERFACES_NAPI_KITS_UTILS_H
17 #define FOUNDATION_ACE_INTERFACES_NAPI_KITS_UTILS_H
18 
19 #include <chrono>
20 #include <cmath>
21 #include <cstdint>
22 #include <regex>
23 #include <vector>
24 
25 #include "native_engine/native_value.h"
26 
27 #include "base/i18n/localization.h"
28 #include "base/log/log.h"
29 #include "bridge/common/utils/utils.h"
30 #include "core/common/container.h"
31 
32 namespace OHOS::Ace::Napi {
33 
34 struct ResourceInfo {
35     int32_t resId = 0;
36     int32_t type = 0;
37     std::vector<std::string> params;
38     std::optional<std::string> bundleName = std::nullopt;
39     std::optional<std::string> moduleName = std::nullopt;
40 };
41 
42 size_t GetParamLen(napi_value param);
43 bool GetNapiString(napi_env env, napi_value value, std::string& retStr, napi_valuetype& valueType);
44 
45 void NapiThrow(napi_env env, const std::string& message, int32_t errCode);
46 
47 bool ParseResourceParam(napi_env env, napi_value value, ResourceInfo& info);
48 
49 bool ParseString(const ResourceInfo& info, std::string& result);
50 
51 std::string ErrorToMessage(int32_t code);
52 
53 } // namespace OHOS::Ace::Napi
54 
55 #endif // FOUNDATION_ACE_INTERFACES_NAPI_KITS_UTILS_H
56