8
0

longtext.js 882 B

1234567891011121314151617181920
  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. import longtext from './longtext.txt';
  6. /**
  7. * Returns text of a given length.
  8. *
  9. * @param {Number} length Length of the resulting text.
  10. * @param {Boolean} fromStart Whether text should be extracted from the start (or end) of the template string.
  11. * @param {Boolean} reversed Whether given text should be reversed.
  12. * @returns {String} Text of a given length.
  13. */
  14. export default function getLongText( length, fromStart = true, reversed = false ) {
  15. const baseText = longtext.repeat( Math.ceil( length / longtext.length ) );
  16. const text = fromStart ? baseText.substring( 0, length ) : baseText.substring( longtext.length - length );
  17. return reversed ? text.split( '' ).reverse().join( '' ) : text;
  18. }