#ifndef SRC_NODE_URL_PATTERN_H_ #define SRC_NODE_URL_PATTERN_H_ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "ada.h" #include "base_object.h" #include "util.h" #include #include #include namespace node::url_pattern { // By default, ada::url_pattern doesn't ship with any regex library. // Ada has a std::regex implementation, but it is considered unsafe and does // not have a fully compliant ecmascript syntax support. Therefore, Ada // supports passing custom regex provider that conforms to the following // class and function structure. For more information, please look into // url_pattern_regex.h inside github.com/ada-url/ada. class URLPatternRegexProvider { public: using regex_type = v8::Global; static std::optional create_instance(std::string_view pattern, bool ignore_case); static std::optional>> regex_search( std::string_view input, const regex_type& pattern); static bool regex_match(std::string_view input, const regex_type& pattern); }; class URLPattern : public BaseObject { public: URLPattern(Environment* env, v8::Local object, ada::url_pattern&& url_pattern); static void New(const v8::FunctionCallbackInfo& args); // V8 APIs // - Functions static void Exec(const v8::FunctionCallbackInfo& info); static void Test(const v8::FunctionCallbackInfo& info); // - Getters static void Hash(const v8::FunctionCallbackInfo& info); static void Hostname(const v8::FunctionCallbackInfo& info); static void Password(const v8::FunctionCallbackInfo& info); static void Pathname(const v8::FunctionCallbackInfo& info); static void Port(const v8::FunctionCallbackInfo& info); static void Protocol(const v8::FunctionCallbackInfo& info); static void Search(const v8::FunctionCallbackInfo& info); static void Username(const v8::FunctionCallbackInfo& info); static void HasRegexpGroups(const v8::FunctionCallbackInfo& info); void MemoryInfo(MemoryTracker* tracker) const override; SET_MEMORY_INFO_NAME(URLPattern) SET_SELF_SIZE(URLPattern) class URLPatternInit { public: static ada::url_pattern_init FromJsObject(Environment* env, v8::Local obj); static v8::MaybeLocal ToJsObject( Environment* env, const ada::url_pattern_init& init); }; class URLPatternOptions { public: static std::optional FromJsObject( Environment* env, v8::Local obj); }; class URLPatternResult { public: static v8::MaybeLocal ToJSValue( Environment* env, const ada::url_pattern_result& result); }; class URLPatternComponentResult { public: static v8::MaybeLocal ToJSObject( Environment* env, const ada::url_pattern_component_result& result); }; private: ada::url_pattern url_pattern_; // Getter methods v8::MaybeLocal Hash() const; v8::MaybeLocal Hostname() const; v8::MaybeLocal Password() const; v8::MaybeLocal Pathname() const; v8::MaybeLocal Port() const; v8::MaybeLocal Protocol() const; v8::MaybeLocal Search() const; v8::MaybeLocal Username() const; bool HasRegExpGroups() const; // Public API v8::MaybeLocal Exec( Environment* env, const ada::url_pattern_input& input, std::optional& baseURL); // NOLINT (runtime/references) bool Test( Environment* env, const ada::url_pattern_input& input, std::optional& baseURL); // NOLINT (runtime/references) }; } // namespace node::url_pattern #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_URL_PATTERN_H_