Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a module without importing it?

I'm creating a es6 module which extends the RegExp object. I'm using the Object.defineProperties to do it:

Object.defineProperties(RegExp.prototoype, {
  ...
});

I'm not returning anything in this file, because I don't need it since RegExp is global in Node.js, but in the same way I need to import something to run the code that will extend the RegExp.prototype. Do you see the problem?

What is the work around in this case? Just return a export default {}? Isn't this a bad thing? I was thinking about returning the RegExp and overwriting in the import:

import RegExp from '@scope/regexp';

Thank you.

like image 650
FXux Avatar asked Aug 31 '25 20:08

FXux


1 Answers

You can use

import '@scope/regex';

This will just run the code in the module, without importing anything.

like image 155
Tsvetan Ganev Avatar answered Sep 03 '25 11:09

Tsvetan Ganev