runtime.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * JavaScript Templates Runtime
  3. * https://github.com/blueimp/JavaScript-Templates
  4. *
  5. * Copyright 2011, Sebastian Tschan
  6. * https://blueimp.net
  7. *
  8. * Licensed under the MIT license:
  9. * https://opensource.org/licenses/MIT
  10. */
  11. /* global define */
  12. ;(function ($) {
  13. 'use strict'
  14. var tmpl = function (id, data) {
  15. var f = tmpl.cache[id]
  16. return data ? f(data, tmpl) : function (data) {
  17. return f(data, tmpl)
  18. }
  19. }
  20. tmpl.cache = {}
  21. tmpl.encReg = /[<>&"'\x00]/g // eslint-disable-line no-control-regex
  22. tmpl.encMap = {
  23. '<': '&lt;',
  24. '>': '&gt;',
  25. '&': '&amp;',
  26. '"': '&quot;',
  27. "'": '&#39;'
  28. }
  29. tmpl.encode = function (s) {
  30. return (s == null ? '' : '' + s).replace(
  31. tmpl.encReg,
  32. function (c) {
  33. return tmpl.encMap[c] || ''
  34. }
  35. )
  36. }
  37. if (typeof define === 'function' && define.amd) {
  38. define(function () {
  39. return tmpl
  40. })
  41. } else if (typeof module === 'object' && module.exports) {
  42. module.exports = tmpl
  43. } else {
  44. $.tmpl = tmpl
  45. }
  46. }(this))