UNPKG

881 BJavaScriptView Raw
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 *
9 * @emails oncall+draft_js
10 */
11'use strict';
12
13/**
14 * Maintain persistence for target list when appending and prepending.
15 */
16function insertIntoList(targetListArg, toInsert, offset) {
17 var targetList = targetListArg;
18
19 if (offset === targetList.count()) {
20 toInsert.forEach(function (c) {
21 targetList = targetList.push(c);
22 });
23 } else if (offset === 0) {
24 toInsert.reverse().forEach(function (c) {
25 targetList = targetList.unshift(c);
26 });
27 } else {
28 var head = targetList.slice(0, offset);
29 var tail = targetList.slice(offset);
30 targetList = head.concat(toInsert, tail).toList();
31 }
32
33 return targetList;
34}
35
36module.exports = insertIntoList;
\No newline at end of file