You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.1 KiB

  1. # options.js #
  2. A very light-weight in-code option parsers for node.js.
  3. ## Usage ##
  4. ``` js
  5. var Options = require("options");
  6. // Create an Options object
  7. function foo(options) {
  8. var default_options = {
  9. foo : "bar"
  10. };
  11. // Create an option object with default value
  12. var opts = new Options(default_options);
  13. // Merge options
  14. opts = opts.merge(options);
  15. // Reset to default value
  16. opts.reset();
  17. // Copy selected attributes out
  18. var seled_att = opts.copy("foo");
  19. // Read json options from a file.
  20. opts.read("options.file"); // Sync
  21. opts.read("options.file", function(err){ // Async
  22. if(err){ // If error occurs
  23. console.log("File error.");
  24. }else{
  25. // No error
  26. }
  27. });
  28. // Attributes defined or not
  29. opts.isDefinedAndNonNull("foobar");
  30. opts.isDefined("foobar");
  31. }
  32. ```
  33. ## License ##
  34. (The MIT License)
  35. Copyright (c) 2012 Einar Otto Stangvik <einaros@gmail.com>
  36. Permission is hereby granted, free of charge, to any person obtaining
  37. a copy of this software and associated documentation files (the
  38. 'Software'), to deal in the Software without restriction, including
  39. without limitation the rights to use, copy, modify, merge, publish,
  40. distribute, sublicense, and/or sell copies of the Software, and to
  41. permit persons to whom the Software is furnished to do so, subject to
  42. the following conditions:
  43. The above copyright notice and this permission notice shall be
  44. included in all copies or substantial portions of the Software.
  45. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  46. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  47. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  48. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  49. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  50. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  51. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.