skip to Main Content

TLDR

Given a downloaded vanilla javascript library file, how to locate the alternative in nodejs?
Some example mapping as below

js library nodejs package
sha256.js crypto-js
elliptic.js elliptic
Buffer.js buffer

Detail

I’m forking a git repo here where several javascript libraries was downloaded and used in a nodejs web app.

E.g. sha256.js file as imported here in javascript, the corresponding one for nodejs is crypto-js package as used here – this requires some tens of minute to figure it out

Some libraries will share same names for both; e.g. elliptic as used in js here and sample used in nodejs here

So what is the official way to map the package/library names between vanilla js and nodejs?


My google search on the topic results not helpful.

The similar post I could find is this one but that’s more specific in label-studio package


What I’ve been doing is the google search for the need

i.e.

gg nodejs {package name} alternative to {library name} in javascript

Or copy the usage js code and google search it for nodejs

gg js CryptoJS.SHA256() alternative for nodejs

And of course, that takes maybe hour to figure out, and that will happen for every new package needed to map.

2

Answers


  1. No, there’s no universal solution for this. If the older version of the library includes a license comment at the top of the file, that definitely helps, but some probably won’t. Some may be browser versions of Node builtins, making it even more confusing.

    If there’s config for Bower, JSPM, or some other script or config that deals with dependencies, that could help lead you in the right direction. Finding the earliest commit for a file might also sometimes give you some information. GitHub’s code search is (sometimes) better than Google. But no universal solution, especially since many older libraries aren’t maintained or published as npm packages.

    Login or Signup to reply.
  2. I am not sure I follow.

    https://github.com/brix/crypto-js is a JavaScript library of crypto standards.

    https://www.npmjs.com/package/@aws-crypto/sha256-js is a part of
    https://github.com/aws/aws-sdk-js-crypto-helpers

    Each of them can be used where you need sha256 – one will perhaps be better suited to your need when you want to npm it, the other not.

    I could not find a list of dependencies in the package.json in the project you mention

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search