Keine Beschreibung

index.js 816B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. function createArg(key, val) {
  3. key = key.replace(/[A-Z]/g, '-$&').toLowerCase();
  4. return '--' + key + (val ? '=' + val : '');
  5. };
  6. module.exports = function (opts, excludes, includes) {
  7. var args = [];
  8. Object.keys(opts).forEach(function (key) {
  9. var val = opts[key];
  10. if (Array.isArray(excludes) && excludes.indexOf(key) !== -1) {
  11. return;
  12. }
  13. if (Array.isArray(includes) && includes.indexOf(key) === -1) {
  14. return;
  15. }
  16. if (val === true) {
  17. args.push(createArg(key));
  18. }
  19. if (typeof val === 'string') {
  20. args.push(createArg(key, val));
  21. }
  22. if (typeof val === 'number' && isNaN(val) === false) {
  23. args.push(createArg(key, '' + val));
  24. }
  25. if (Array.isArray(val)) {
  26. val.forEach(function (arrVal) {
  27. args.push(createArg(key, arrVal));
  28. });
  29. }
  30. });
  31. return args;
  32. };