server-cuid.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/ // The require function
  5. /******/ function __webpack_require__(moduleId) {
  6. /******/ // Check if module is in cache
  7. /******/ if(installedModules[moduleId])
  8. /******/ return installedModules[moduleId].exports;
  9. /******/ // Create a new module (and put it into the cache)
  10. /******/ var module = installedModules[moduleId] = {
  11. /******/ exports: {},
  12. /******/ id: moduleId,
  13. /******/ loaded: false
  14. /******/ };
  15. /******/ // Execute the module function
  16. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  17. /******/ // Flag the module as loaded
  18. /******/ module.loaded = true;
  19. /******/ // Return the exports of the module
  20. /******/ return module.exports;
  21. /******/ }
  22. /******/ // expose the modules object (__webpack_modules__)
  23. /******/ __webpack_require__.m = modules;
  24. /******/ // expose the module cache
  25. /******/ __webpack_require__.c = installedModules;
  26. /******/ // __webpack_public_path__
  27. /******/ __webpack_require__.p = "";
  28. /******/ // Load entry module and return exports
  29. /******/ return __webpack_require__(0);
  30. /******/ })
  31. /************************************************************************/
  32. /******/ ([
  33. /* 0 */
  34. /***/ function(module, exports, __webpack_require__) {
  35. 'use strict';
  36. Object.defineProperty(exports, '__esModule', {
  37. value: true
  38. });
  39. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  40. var _indexJs = __webpack_require__(1);
  41. var _indexJs2 = _interopRequireDefault(_indexJs);
  42. var fingerprint = __webpack_require__(2)();
  43. var _createCuid = (0, _indexJs2['default'])(fingerprint);
  44. var cuid = _createCuid.cuid;
  45. var slug = _createCuid.slug;
  46. cuid.slug = slug;
  47. exports['default'] = cuid;
  48. module.exports = exports['default'];
  49. /***/ },
  50. /* 1 */
  51. /***/ function(module, exports) {
  52. /**
  53. * cuid.js
  54. * Collision-resistant UID generator for browsers and node.
  55. * Sequential for fast db lookups and recency sorting.
  56. * Safe for element IDs and server-side lookups.
  57. *
  58. * Extracted from CLCTR
  59. *
  60. * Copyright (c) Eric Elliott 2012
  61. * MIT License
  62. */
  63. 'use strict';
  64. Object.defineProperty(exports, '__esModule', {
  65. value: true
  66. });
  67. var c = 0;
  68. var blockSize = 4;
  69. var base = 36;
  70. var discreteValues = Math.pow(base, blockSize);
  71. var pad = function pad(str, size) {
  72. return ('000000000' + str).slice(-size);
  73. };
  74. var randomBlock = function randomBlock() {
  75. return pad((Math.random() * discreteValues << 0).toString(base), blockSize);
  76. };
  77. var safeCounter = function safeCounter() {
  78. c = c < discreteValues ? c : 0;
  79. return c++;
  80. };
  81. var createCuid = function createCuid(fingerprint) {
  82. var cuid = function cuid() {
  83. // Starting with a lowercase letter makes
  84. // it HTML element ID friendly.
  85. var letter = 'c'; // hard-coded allows for sequential access
  86. // timestamp
  87. // warning: this exposes the exact date and time
  88. // that the uid was created.
  89. var timestamp = new Date().getTime().toString(base);
  90. // Grab some more chars from Math.random()
  91. var random = randomBlock() + randomBlock();
  92. // Prevent same-machine collisions.
  93. var counter = pad(safeCounter().toString(base), blockSize);
  94. return letter + timestamp + counter + fingerprint + random;
  95. };
  96. var slug = function slug() {
  97. var date = new Date().getTime().toString(36);
  98. var print = fingerprint.slice(0, 1) + fingerprint.slice(-1);
  99. var random = randomBlock().slice(-2);
  100. var counter = safeCounter().toString(36).slice(-4);
  101. return date.slice(-2) + counter + print + random;
  102. };
  103. return { cuid: cuid, slug: slug };
  104. };
  105. exports['default'] = createCuid;
  106. module.exports = exports['default'];
  107. /***/ },
  108. /* 2 */
  109. /***/ function(module, exports, __webpack_require__) {
  110. /* WEBPACK VAR INJECTION */(function(process) {'use strict';
  111. Object.defineProperty(exports, '__esModule', {
  112. value: true
  113. });
  114. var os = __webpack_require__(4);
  115. var pad = function pad(str, size) {
  116. return ('000000000' + str).slice(-size);
  117. };
  118. var padding = 2;
  119. var pid = pad(process.pid.toString(36), padding);
  120. var hostname = os.hostname();
  121. hostname = hostname.split('').reduce(function (prev, char) {
  122. return +prev + char.charCodeAt(0);
  123. }, +hostname.length + 36).toString(36);
  124. var hostId = pad(hostname, padding);
  125. exports['default'] = function () {
  126. return pid + hostId;
  127. };
  128. module.exports = exports['default'];
  129. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))
  130. /***/ },
  131. /* 3 */
  132. /***/ function(module, exports) {
  133. // shim for using process in browser
  134. var process = module.exports = {};
  135. var queue = [];
  136. var draining = false;
  137. var currentQueue;
  138. var queueIndex = -1;
  139. function cleanUpNextTick() {
  140. draining = false;
  141. if (currentQueue.length) {
  142. queue = currentQueue.concat(queue);
  143. } else {
  144. queueIndex = -1;
  145. }
  146. if (queue.length) {
  147. drainQueue();
  148. }
  149. }
  150. function drainQueue() {
  151. if (draining) {
  152. return;
  153. }
  154. var timeout = setTimeout(cleanUpNextTick);
  155. draining = true;
  156. var len = queue.length;
  157. while(len) {
  158. currentQueue = queue;
  159. queue = [];
  160. while (++queueIndex < len) {
  161. currentQueue[queueIndex].run();
  162. }
  163. queueIndex = -1;
  164. len = queue.length;
  165. }
  166. currentQueue = null;
  167. draining = false;
  168. clearTimeout(timeout);
  169. }
  170. process.nextTick = function (fun) {
  171. var args = new Array(arguments.length - 1);
  172. if (arguments.length > 1) {
  173. for (var i = 1; i < arguments.length; i++) {
  174. args[i - 1] = arguments[i];
  175. }
  176. }
  177. queue.push(new Item(fun, args));
  178. if (queue.length === 1 && !draining) {
  179. setTimeout(drainQueue, 0);
  180. }
  181. };
  182. // v8 likes predictible objects
  183. function Item(fun, array) {
  184. this.fun = fun;
  185. this.array = array;
  186. }
  187. Item.prototype.run = function () {
  188. this.fun.apply(null, this.array);
  189. };
  190. process.title = 'browser';
  191. process.browser = true;
  192. process.env = {};
  193. process.argv = [];
  194. process.version = ''; // empty string to avoid regexp issues
  195. process.versions = {};
  196. function noop() {}
  197. process.on = noop;
  198. process.addListener = noop;
  199. process.once = noop;
  200. process.off = noop;
  201. process.removeListener = noop;
  202. process.removeAllListeners = noop;
  203. process.emit = noop;
  204. process.binding = function (name) {
  205. throw new Error('process.binding is not supported');
  206. };
  207. // TODO(shtylman)
  208. process.cwd = function () { return '/' };
  209. process.chdir = function (dir) {
  210. throw new Error('process.chdir is not supported');
  211. };
  212. process.umask = function() { return 0; };
  213. /***/ },
  214. /* 4 */
  215. /***/ function(module, exports) {
  216. exports.endianness = function () { return 'LE' };
  217. exports.hostname = function () {
  218. if (typeof location !== 'undefined') {
  219. return location.hostname
  220. }
  221. else return '';
  222. };
  223. exports.loadavg = function () { return [] };
  224. exports.uptime = function () { return 0 };
  225. exports.freemem = function () {
  226. return Number.MAX_VALUE;
  227. };
  228. exports.totalmem = function () {
  229. return Number.MAX_VALUE;
  230. };
  231. exports.cpus = function () { return [] };
  232. exports.type = function () { return 'Browser' };
  233. exports.release = function () {
  234. if (typeof navigator !== 'undefined') {
  235. return navigator.appVersion;
  236. }
  237. return '';
  238. };
  239. exports.networkInterfaces
  240. = exports.getNetworkInterfaces
  241. = function () { return {} };
  242. exports.arch = function () { return 'javascript' };
  243. exports.platform = function () { return 'browser' };
  244. exports.tmpdir = exports.tmpDir = function () {
  245. return '/tmp';
  246. };
  247. exports.EOL = '\n';
  248. /***/ }
  249. /******/ ]);