File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,24 @@ import replace from '@rollup/plugin-replace';
15
15
import { terser } from 'rollup-plugin-terser' ;
16
16
import typescript from 'rollup-plugin-typescript2' ;
17
17
18
+ /**
19
+ * Helper functions to compensate for the fact that JS can't handle negative array indices very well
20
+ *
21
+ * TODO `insertAt` is only exported so the integrations config can inject the `commonjs` plugin, for localforage (used
22
+ * in the offline plugin). Once that's fixed to no longer be necessary, this can stop being exported.
23
+ */
24
+ function getLastElement ( array ) {
25
+ return array [ array . length - 1 ] ;
26
+ }
27
+ export function insertAt ( arr , index , insertee ) {
28
+ const newArr = [ ...arr ] ;
29
+ // Add 1 to the array length so that the inserted element ends up in the right spot with respect to the length of the
30
+ // new array (which will be one element longer), rather than that of the current array
31
+ const destinationIndex = index >= 0 ? index : arr . length + 1 + index ;
32
+ newArr . splice ( destinationIndex , 0 , insertee ) ;
33
+ return newArr ;
34
+ }
35
+
18
36
/**
19
37
* Create a plugin to add an identification banner to the top of stand-alone bundles.
20
38
*
You can’t perform that action at this time.
0 commit comments