File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -30,13 +30,28 @@ napi_status napi_emplace_named_property_object(napi_env env,
3030 return status;
3131}
3232
33+ bool endsWith (const std::string &str, const std::string &suffix) {
34+ #if __cplusplus >= 202002L // __cpp_lib_starts_ends_with
35+ return str.ends_with (suffix);
36+ #else
37+ return str.size () >= suffix.size ()
38+ && std::equal (suffix.rbegin (), suffix.rend (), str.rbegin ());
39+ #endif
40+ }
41+
42+ std::string_view stripSuffix (const std::string_view &str, const std::string_view &suffix) {
43+ if (endsWith (str, suffix)) {
44+ return str.substr (0 , str.size () - suffix.size ());
45+ } else {
46+ return str;
47+ }
48+ }
49+
3350void sanitizeLibraryNameInplace (std::string &name) {
3451#if USING_PATCHED_BABEL_PLUGIN
3552 // Strip the extension (if present)
3653 // NOTE: This is needed when working with updated Babel plugin
37- if (auto pos = name.find (" .node" ); std::string::npos != pos) {
38- name = name.substr (0 , pos);
39- }
54+ name = stripSuffix (name, " .node" );
4055#endif
4156
4257 for (char &c : name) {
You can’t perform that action at this time.
0 commit comments