This is a great question and something I've wondered myself. Since you mentioned JS, I implemented this on a branch of bcoin: https://github.com/pinheadmz/bcoin/commit/ec1f5c95bb76f86aa034ec5a288fc09dd15d9597
$ bcoin --prune --daemon
$ bcoin-cli rpc getblockchaininfo
$ bcoin-cli block 1000
It is not possible to verify just a single transaction, without knowing the state of the network. To know the state of the network, you must verify all of it's historical transactions (aka, run a full node).
So this means it is not possible to just take a single transaction alone, and verify it using some bit of code. Rather, you will need the entire ...