Inline nub helper, drop runtime dependency#54
Conversation
The nub module is used in a single call site to dedupe a flat array of country name strings. Inlining an equivalent three-line ES5 helper lets us drop the runtime dependency without changing behavior or platform requirements. Tests pass locally.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR removes the external nub dependency and replaces it with an inline implementation to deduplicate arrays.
Changes:
- Dropped
nubfrompackage.jsondependencies. - Replaced
require('nub')with a localnubfunction inindex.js.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| package.json | Removes the nub dependency from runtime dependencies. |
| index.js | Adds an inline array-deduplication helper to replace nub. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var publishDate = require('./iso-4217-publish-date'); | ||
|
|
||
| var nub = function(xs) { | ||
| return xs.filter(function(x, i) { return xs.indexOf(x) === i; }); |
There was a problem hiding this comment.
This implementation is equivalent to the implementation in the existing nub@0.0.0 package. I'd recommend against a solution that assumes the existence of Set so the code will continue working for any consumer running ES5.
| var data = require('./data'); | ||
| var publishDate = require('./iso-4217-publish-date'); | ||
|
|
||
| var nub = function(xs) { |
|
Hey @colinhacks, that library does not seem maintained anymore. I have a PR waiting for more than a year now (#48). If you want to drop that dependency and have up to date data, please consider testing that fork that has the same API and is auto-refreshed weekly: https://github.com/adesurirey/fresh-currency-codes |
nubis used in a single call site to dedupe the flat list of country names returned bycountries(). Inlining a three-line ES5 equivalent lets us drop the runtime dependency without changing behavior or platform requirements.The local helper uses
Array.prototype.filter+Array.prototype.indexOf, both ES5, both already used elsewhere inindex.js, so this introduces no new engine requirements.Tests pass locally —
cc.countries().length === 260continues to hold, which is the assertion that exercises the deduplication path.