utility.js 499 B

12345678910111213141516171819202122232425
  1. // copy from https://github.com/node-modules/utility for browser
  2. exports.encodeURIComponent = function (text) {
  3. try {
  4. return encodeURIComponent(text);
  5. } catch (e) {
  6. return text;
  7. }
  8. };
  9. exports.escape = require('escape-html');
  10. exports.timestamp = function timestamp(t) {
  11. if (t) {
  12. var v = t;
  13. if (typeof v === 'string') {
  14. v = Number(v);
  15. }
  16. if (String(t).length === 10) {
  17. v *= 1000;
  18. }
  19. return new Date(v);
  20. }
  21. return Math.round(Date.now() / 1000);
  22. };