|
- /**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @format
- *
- * @emails oncall+draft_js
- */
- 'use strict';
-
- var UnicodeUtils = require("fbjs/lib/UnicodeUtils");
-
- var substr = UnicodeUtils.substr;
- /**
- * Convert to native JavaScript string lengths to determine ranges.
- */
-
- function decodeEntityRanges(text, ranges) {
- var entities = Array(text.length).fill(null);
-
- if (ranges) {
- ranges.forEach(function (range) {
- // Using Unicode-enabled substrings converted to JavaScript lengths,
- // fill the output array with entity keys.
- var start = substr(text, 0, range.offset).length;
- var end = start + substr(text, range.offset, range.length).length;
-
- for (var ii = start; ii < end; ii++) {
- entities[ii] = range.key;
- }
- });
- }
-
- return entities;
- }
-
- module.exports = decodeEntityRanges;
|