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 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 #ifndef JS_UTILS_H 16 #define JS_UTILS_H 17 18 #include <map> 19 #include "napi/native_api.h" 20 #include "napi/native_node_api.h" 21 22 namespace OHOS { 23 namespace Global { 24 namespace I18n { 25 class JSUtils { 26 public: 27 static napi_value DefaultConstructor(napi_env env, napi_callback_info info); 28 static napi_value CreateEmptyString(napi_env env); 29 static void GetOptionValue(napi_env env, napi_value options, const std::string &optionName, 30 std::map<std::string, std::string> &map); 31 static void GetBoolOptionValue(napi_env env, napi_value options, const std::string &optionName, 32 std::map<std::string, std::string> &map); 33 static std::string GetLocaleTag(napi_env env, napi_value argv); 34 static void GetLocaleTags(napi_env env, napi_value rawLocaleTag, std::vector<std::string> &localeTags); 35 36 static void GetNumberOptionValues(napi_env env, napi_value options, std::map<std::string, std::string> &map); 37 static int64_t GetIntegerOptionValue(napi_env env, napi_value options, const std::string &optionName, 38 std::map<std::string, std::string> &map); 39 40 static void SetOptionProperties(napi_env env, napi_value &result, 41 std::map<std::string, std::string> &options, const std::string &option); 42 static void SetBooleanOptionProperties(napi_env env, napi_value &result, 43 std::map<std::string, std::string> &options, const std::string &option); 44 static void SetIntegerOptionProperties(napi_env env, napi_value &result, 45 std::map<std::string, std::string> &options, const std::string &option); 46 }; 47 } // namespace I18n 48 } // namespace Global 49 } // namespace OHOS 50 #endif