runtime.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. /* eslint-disable strict */
  13. ;(function($) {
  14. 'use strict'
  15. var tmpl = function(id, data) {
  16. var f = tmpl.cache[id]
  17. return data
  18. ? f(data, tmpl)
  19. : function(data) {
  20. return f(data, tmpl)
  21. }
  22. }
  23. tmpl.cache = {}
  24. tmpl.encReg = /[<>&"'\x00]/g // eslint-disable-line no-control-regex
  25. tmpl.encMap = {
  26. '<': '&lt;',
  27. '>': '&gt;',
  28. '&': '&amp;',
  29. '"': '&quot;',
  30. "'": '&#39;'
  31. }
  32. tmpl.encode = function(s) {
  33. // eslint-disable-next-line eqeqeq
  34. return (s == null ? '' : '' + s).replace(tmpl.encReg, function(c) {
  35. return tmpl.encMap[c] || ''
  36. })
  37. }
  38. if (typeof define === 'function' && define.amd) {
  39. define(function() {
  40. return tmpl
  41. })
  42. } else if (typeof module === 'object' && module.exports) {
  43. module.exports = tmpl
  44. } else {
  45. $.tmpl = tmpl
  46. }
  47. })(this)