• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 NAPI_API_ENV_H
17 #define NAPI_API_ENV_H
18 
19 #ifdef __OHOS_PLATFORM__
20 #include "napi/native_api.h"
21 #else
22 #include <node_api.h>
23 #endif
24 
25 #include <base/containers/string.h>
26 
27 namespace NapiApi {
28 
29 class Env {
30 public:
31     Env() = default;
32     explicit Env(napi_env env);
33 
34     operator bool() const;
35     operator napi_env() const;
36 
37     napi_value GetNull() const;
38     napi_value GetUndefined() const;
39     napi_value GetBoolean(bool value) const;
40     napi_value GetString(const BASE_NS::string_view value) const;
41 
42     napi_value GetNumber(uint32_t value) const;
43     napi_value GetNumber(int32_t value) const;
44     napi_value GetNumber(uint64_t value) const;
45     napi_value GetNumber(int64_t value) const;
46     napi_value GetNumber(float value) const;
47     napi_value GetNumber(double value) const;
48 
49 private:
50     napi_env env_ { nullptr };
51 };
52 
53 } // namespace NapiApi
54 
55 #endif
56