Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

43 строки
1.1 KiB

  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. import type { EntityRange } from "./EntityRange";
  13. const UnicodeUtils = require("fbjs/lib/UnicodeUtils");
  14. const {
  15. substr
  16. } = UnicodeUtils;
  17. /**
  18. * Convert to native JavaScript string lengths to determine ranges.
  19. */
  20. function decodeEntityRanges(text: string, ranges: Array<EntityRange>): Array<?string> {
  21. const entities = Array(text.length).fill(null);
  22. if (ranges) {
  23. ranges.forEach(range => {
  24. // Using Unicode-enabled substrings converted to JavaScript lengths,
  25. // fill the output array with entity keys.
  26. const start = substr(text, 0, range.offset).length;
  27. const end = start + substr(text, range.offset, range.length).length;
  28. for (let ii = start; ii < end; ii++) {
  29. entities[ii] = range.key;
  30. }
  31. });
  32. }
  33. return entities;
  34. }
  35. module.exports = decodeEntityRanges;