@dotcom-tool-kit/conflict 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +31 -0
- package/package.json +15 -0
- package/src/index.ts +40 -0
- package/tsconfig.json +12 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Plugin } from '@dotcom-tool-kit/plugin';
|
|
2
|
+
export interface Conflict<T> {
|
|
3
|
+
plugin: Plugin;
|
|
4
|
+
conflicting: T[];
|
|
5
|
+
}
|
|
6
|
+
export declare function isConflict<T>(thing: unknown): thing is Conflict<T>;
|
|
7
|
+
export declare function findConflictingEntries<T, U>(items: Record<string, U | Conflict<T>>): [string, Conflict<T>][];
|
|
8
|
+
export declare function findConflicts<T, U>(items: (U | Conflict<T>)[]): Conflict<T>[];
|
|
9
|
+
export declare function withoutConflicts<T, U>(items: (U | Conflict<T>)[]): U[];
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAErD,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,CAAC,EAAE,CAAA;CACjB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAElE;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,CAAC,EACzC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,GACrC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAEzB;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAU7E;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAUtE"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withoutConflicts = exports.findConflicts = exports.findConflictingEntries = exports.isConflict = void 0;
|
|
4
|
+
function isConflict(thing) {
|
|
5
|
+
return Boolean(thing.conflicting);
|
|
6
|
+
}
|
|
7
|
+
exports.isConflict = isConflict;
|
|
8
|
+
function findConflictingEntries(items) {
|
|
9
|
+
return Object.entries(items).filter((entry) => isConflict(entry[1]));
|
|
10
|
+
}
|
|
11
|
+
exports.findConflictingEntries = findConflictingEntries;
|
|
12
|
+
function findConflicts(items) {
|
|
13
|
+
const conflicts = [];
|
|
14
|
+
for (const item of items) {
|
|
15
|
+
if (isConflict(item)) {
|
|
16
|
+
conflicts.push(item);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return conflicts;
|
|
20
|
+
}
|
|
21
|
+
exports.findConflicts = findConflicts;
|
|
22
|
+
function withoutConflicts(items) {
|
|
23
|
+
const nonConflicts = [];
|
|
24
|
+
for (const item of items) {
|
|
25
|
+
if (!isConflict(item)) {
|
|
26
|
+
nonConflicts.push(item);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return nonConflicts;
|
|
30
|
+
}
|
|
31
|
+
exports.withoutConflicts = withoutConflicts;
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dotcom-tool-kit/conflict",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@dotcom-tool-kit/plugin": "2.0.0-beta.0"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Plugin } from '@dotcom-tool-kit/plugin'
|
|
2
|
+
|
|
3
|
+
export interface Conflict<T> {
|
|
4
|
+
plugin: Plugin
|
|
5
|
+
conflicting: T[]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function isConflict<T>(thing: unknown): thing is Conflict<T> {
|
|
9
|
+
return Boolean((thing as Conflict<T>).conflicting)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function findConflictingEntries<T, U>(
|
|
13
|
+
items: Record<string, U | Conflict<T>>
|
|
14
|
+
): [string, Conflict<T>][] {
|
|
15
|
+
return Object.entries(items).filter((entry): entry is [string, Conflict<T>] => isConflict(entry[1]))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function findConflicts<T, U>(items: (U | Conflict<T>)[]): Conflict<T>[] {
|
|
19
|
+
const conflicts: Conflict<T>[] = []
|
|
20
|
+
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
if (isConflict<T>(item)) {
|
|
23
|
+
conflicts.push(item)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return conflicts
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function withoutConflicts<T, U>(items: (U | Conflict<T>)[]): U[] {
|
|
31
|
+
const nonConflicts: U[] = []
|
|
32
|
+
|
|
33
|
+
for (const item of items) {
|
|
34
|
+
if (!isConflict<T>(item)) {
|
|
35
|
+
nonConflicts.push(item)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return nonConflicts
|
|
40
|
+
}
|