first.js 482 B

123456789101112131415161718192021222324
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module utils/first
  7. */
  8. /**
  9. * Returns first item of the given `iterable`.
  10. *
  11. * @param {Iterable.<*>} iterable
  12. * @returns {*}
  13. */
  14. export default function first( iterable ) {
  15. const iteratorItem = iterable.next();
  16. if ( iteratorItem.done ) {
  17. return null;
  18. }
  19. return iteratorItem.value;
  20. }