0

Newbie question, I'm working with a npm package and I would like to modify the original function but haven't got much luck trying. The function I'm trying to modify:

AnimationItem.prototype.getMarkerData = (markerName: string) => {
  let marker;
  for (let i = 0; i < this.markers.length; i += 1) {
    marker = this.markers[i];
    if (marker.payload && marker.payload.name === markerName) {
      return marker;
    }
  }
  return null;
};

I want to replace this condition:

if (marker.payload && marker.payload.name === markerName)

with this:

if (marker.payload && marker.payload.name.cm === markerName)

Things I've tried so far:

  • Use patch-package: I got some weird error similar to this but haven't got any fix so far.

I'm trying to override the prototype locally in my React component (until the PR to fix this issue is merge in the source code) but I'm not sure how should I go about it, any suggestion would be appreciated! Thanks.

1 Answers1

0

You can try moving the package to a different directory (or git cloning it) in your computer, then make your changes inside, change it's name/version inside the package.json file then link it with npm link. After linking it, you can go back to your project and install the package with new name/version (npm install packagename , npm install packagename@version).

Or you can fork it, make your changes then install the dependency from a git URL. Here is an example of how you can install a package from a git URL.

archon
  • 183
  • 8