utils.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. /**
  7. * A utilities library.
  8. *
  9. * @class utils
  10. * @singleton
  11. */
  12. CKEDITOR.define( [ 'utils-lodash', 'lib/lodash/lodash-ckeditor' ], function( lodashIncludes, lodash ) {
  13. var utils = {
  14. /**
  15. * Creates a spy function (ala Sinon.js) that can be used to inspect call to it.
  16. *
  17. * The following are the present features:
  18. *
  19. * * spy.called: property set to `true` if the function has been called at least once.
  20. *
  21. * @returns {Function} The spy function.
  22. */
  23. spy: function() {
  24. var spy = function() {
  25. spy.called = true;
  26. };
  27. return spy;
  28. },
  29. /**
  30. * Returns a unique id. This id is a number (starting from 1) which will never get repeated on successive calls
  31. * to this method.
  32. *
  33. * @returns {Number} A number representing the id.
  34. */
  35. uid: ( function() {
  36. var next = 1;
  37. return function() {
  38. return next++;
  39. };
  40. } )()
  41. };
  42. // Extend "utils" with Lo-Dash methods.
  43. for ( var i = 0; i < lodashIncludes.length; i++ ) {
  44. utils[ lodashIncludes[ i ] ] = lodash[ lodashIncludes[ i ] ];
  45. }
  46. return utils;
  47. } );