index.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*jshint node:true */
  2. /* globals define */
  3. /*
  4. The MIT License (MIT)
  5. Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
  6. Permission is hereby granted, free of charge, to any person
  7. obtaining a copy of this software and associated documentation files
  8. (the "Software"), to deal in the Software without restriction,
  9. including without limitation the rights to use, copy, modify, merge,
  10. publish, distribute, sublicense, and/or sell copies of the Software,
  11. and to permit persons to whom the Software is furnished to do so,
  12. subject to the following conditions:
  13. The above copyright notice and this permission notice shall be
  14. included in all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. SOFTWARE.
  23. */
  24. 'use strict';
  25. /**
  26. The following batches are equivalent:
  27. var beautify_js = require('js-beautify');
  28. var beautify_js = require('js-beautify').js;
  29. var beautify_js = require('js-beautify').js_beautify;
  30. var beautify_css = require('js-beautify').css;
  31. var beautify_css = require('js-beautify').css_beautify;
  32. var beautify_html = require('js-beautify').html;
  33. var beautify_html = require('js-beautify').html_beautify;
  34. All methods returned accept two arguments, the source string and an options object.
  35. **/
  36. function get_beautify(js_beautify, css_beautify, html_beautify) {
  37. // the default is js
  38. var beautify = function(src, config) {
  39. return js_beautify.js_beautify(src, config);
  40. };
  41. // short aliases
  42. beautify.js = js_beautify.js_beautify;
  43. beautify.css = css_beautify.css_beautify;
  44. beautify.html = html_beautify.html_beautify;
  45. // legacy aliases
  46. beautify.js_beautify = js_beautify.js_beautify;
  47. beautify.css_beautify = css_beautify.css_beautify;
  48. beautify.html_beautify = html_beautify.html_beautify;
  49. return beautify;
  50. }
  51. if (typeof define === "function" && define.amd) {
  52. // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
  53. define([
  54. "./lib/beautify",
  55. "./lib/beautify-css",
  56. "./lib/beautify-html"
  57. ], function(js_beautify, css_beautify, html_beautify) {
  58. return get_beautify(js_beautify, css_beautify, html_beautify);
  59. });
  60. } else {
  61. (function(mod) {
  62. var beautifier = require('./src/index');
  63. beautifier.js_beautify = beautifier.js;
  64. beautifier.css_beautify = beautifier.css;
  65. beautifier.html_beautify = beautifier.html;
  66. mod.exports = get_beautify(beautifier, beautifier, beautifier);
  67. })(module);
  68. }