Dashboard sipadu mbip
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

dedupe.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*!
  2. Copyright (c) 2017 Jed Watson.
  3. Licensed under the MIT License (MIT), see
  4. http://jedwatson.github.io/classnames
  5. */
  6. /* global define */
  7. (function () {
  8. 'use strict';
  9. var classNames = (function () {
  10. // don't inherit from Object so we can skip hasOwnProperty check later
  11. // http://stackoverflow.com/questions/15518328/creating-js-object-with-object-createnull#answer-21079232
  12. function StorageObject() {}
  13. StorageObject.prototype = Object.create(null);
  14. function _parseArray (resultSet, array) {
  15. var length = array.length;
  16. for (var i = 0; i < length; ++i) {
  17. _parse(resultSet, array[i]);
  18. }
  19. }
  20. var hasOwn = {}.hasOwnProperty;
  21. function _parseNumber (resultSet, num) {
  22. resultSet[num] = true;
  23. }
  24. function _parseObject (resultSet, object) {
  25. for (var k in object) {
  26. if (hasOwn.call(object, k)) {
  27. // set value to false instead of deleting it to avoid changing object structure
  28. // https://www.smashingmagazine.com/2012/11/writing-fast-memory-efficient-javascript/#de-referencing-misconceptions
  29. resultSet[k] = !!object[k];
  30. }
  31. }
  32. }
  33. var SPACE = /\s+/;
  34. function _parseString (resultSet, str) {
  35. var array = str.split(SPACE);
  36. var length = array.length;
  37. for (var i = 0; i < length; ++i) {
  38. resultSet[array[i]] = true;
  39. }
  40. }
  41. function _parse (resultSet, arg) {
  42. if (!arg) return;
  43. var argType = typeof arg;
  44. // 'foo bar'
  45. if (argType === 'string') {
  46. _parseString(resultSet, arg);
  47. // ['foo', 'bar', ...]
  48. } else if (Array.isArray(arg)) {
  49. _parseArray(resultSet, arg);
  50. // { 'foo': true, ... }
  51. } else if (argType === 'object') {
  52. _parseObject(resultSet, arg);
  53. // '130'
  54. } else if (argType === 'number') {
  55. _parseNumber(resultSet, arg);
  56. }
  57. }
  58. function _classNames () {
  59. // don't leak arguments
  60. // https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments
  61. var len = arguments.length;
  62. var args = Array(len);
  63. for (var i = 0; i < len; i++) {
  64. args[i] = arguments[i];
  65. }
  66. var classSet = new StorageObject();
  67. _parseArray(classSet, args);
  68. var list = [];
  69. for (var k in classSet) {
  70. if (classSet[k]) {
  71. list.push(k)
  72. }
  73. }
  74. return list.join(' ');
  75. }
  76. return _classNames;
  77. })();
  78. if (typeof module !== 'undefined' && module.exports) {
  79. classNames.default = classNames;
  80. module.exports = classNames;
  81. } else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
  82. // register as 'classnames', consistent with npm package name
  83. define('classnames', [], function () {
  84. return classNames;
  85. });
  86. } else {
  87. window.classNames = classNames;
  88. }
  89. }());