Source.js 569 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. class Source {
  7. source() {
  8. throw new Error("Abstract");
  9. }
  10. buffer() {
  11. const source = this.source();
  12. if (Buffer.isBuffer(source)) return source;
  13. return Buffer.from(source, "utf-8");
  14. }
  15. size() {
  16. return this.buffer().length;
  17. }
  18. map(options) {
  19. return null;
  20. }
  21. sourceAndMap(options) {
  22. return {
  23. source: this.source(),
  24. map: this.map(options)
  25. };
  26. }
  27. updateHash(hash) {
  28. throw new Error("Abstract");
  29. }
  30. }
  31. module.exports = Source;