Skip to content

Commit b44ff04

Browse files
committed
fix: move utils function
1 parent ca8bc5c commit b44ff04

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/main.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { includesAny } from "./utils"
2+
13
// common plugins
24
import type resolve from "@rollup/plugin-node-resolve"
35
import type commonjs from "@rollup/plugin-commonjs"
@@ -36,26 +38,6 @@ export type Plugin =
3638
| ["terser", typeof terser]
3739
| ["replace", typeof replace]
3840

39-
// function to check if the first array has any of the second array
40-
// first array can have `[string, object]` as their input
41-
function includesAny(arr1: Array<string | [string, Object]>, arr2: Array<string>): null | number {
42-
for (let index = 0; index < arr1.length; index++) {
43-
const elm = arr1[index]
44-
let name: string
45-
if (typeof elm === "string") {
46-
// plugin name only
47-
name = elm
48-
} else {
49-
// plugin with options
50-
name = elm[0]
51-
}
52-
if (arr2.includes(name)) {
53-
return index
54-
}
55-
}
56-
return null
57-
}
58-
5941
export function createPlugins(
6042
inputPluginsNames: Array<Plugin> = ["ts", "js", "json", "coffee"],
6143
extraPlugins?: Array<any> | boolean,

src/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// function to check if the first array has any of the second array
2+
// first array can have `[string, object]` as their input
3+
export function includesAny(arr1: Array<string | [string, Object]>, arr2: Array<string>): null | number {
4+
for (let index = 0; index < arr1.length; index++) {
5+
const elm = arr1[index]
6+
let name: string
7+
if (typeof elm === "string") {
8+
// plugin name only
9+
name = elm
10+
} else {
11+
// plugin with options
12+
name = elm[0]
13+
}
14+
if (arr2.includes(name)) {
15+
return index
16+
}
17+
}
18+
return null
19+
}

0 commit comments

Comments
 (0)