A simple NHS number validator, following the process described in the NHS Data Dictionary.
npm install --save nhs-number-validatorbower install --save nhs-number-validatorTo run the interactive validation tool, install the NPM module globally:
npm install -g nhs-number-validatorand nhs-number-validator will be added to your path:
$ nhs-number-validator
Enter NHS numbers to validate, Ctrl-D to exit
> 123
*INVALID
> 2983396339
VALIDYou can also install the tool for a single project, and just reference the executable in your project:
npm install nhs-number-validator
./node_modules/.bin/nhs-number-validator
# or
`npm bin`/nhs-number-validatorFor environments supporting require/exports:
var validator = require('nhs-number-validator');
validator.validate('2983396339') // => true
validator.validate('test') // => falseAny environment which exposes window will have the nhsNumberValidator variable attached when index.js is loaded, e.g.:
<script src="./bower_components/nhs-number-validator/index.js"></script>
<script>
var validator = window.nhsNumberValidator
validator.validate('2983396339') // => true
validator.validate('test') // => false
// or just use it directly if you prefer:
window.nhsNumberValidator.validate('2983396339') // => true
// you don't even need `window`:
nhsNumberValidator.validate('2983396339') // => true
</script>Pull requests, issues, and questions are all welcome.
Some useful commands:
npm test: run the test suite.npm run test-watch --silent: watch for changes and run the test suite each time.npm run lint --silent: run the code linter.npm run cli: run the validator CLI.
NPM is overly verbose at the moment, hence the additional --silent to suppress the unnecessary noise.
Making a release is pretty straightforward:
- Update the version in
package.jsonin themainbranch. - Tag the commit with the same version number (e.g.
git tag -l "1.1.1" && git push --tags), which will trigger GitHub Actions to publish to NPM.