nopt.js 955 B

123456789101112131415161718192021222324252627282930
  1. const lib = require('./nopt-lib')
  2. const defaultTypeDefs = require('./type-defs')
  3. // This is the version of nopt's API that requires setting typeDefs and invalidHandler
  4. // on the required `nopt` object since it is a singleton. To not do a breaking change
  5. // an API that requires all options be passed in is located in `nopt-lib.js` and
  6. // exported here as lib.
  7. // TODO(breaking): make API only work in non-singleton mode
  8. module.exports = exports = nopt
  9. exports.clean = clean
  10. exports.typeDefs = defaultTypeDefs
  11. exports.lib = lib
  12. function nopt (types, shorthands, args = process.argv, slice = 2) {
  13. return lib.nopt(args.slice(slice), {
  14. types: types || {},
  15. shorthands: shorthands || {},
  16. typeDefs: exports.typeDefs,
  17. invalidHandler: exports.invalidHandler,
  18. })
  19. }
  20. function clean (data, types, typeDefs = exports.typeDefs) {
  21. return lib.clean(data, {
  22. types: types || {},
  23. typeDefs,
  24. invalidHandler: exports.invalidHandler,
  25. })
  26. }