@knotx/utils 0.2.7 → 0.2.9
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/dist/index.cjs +8 -0
- package/dist/index.d.cts +11 -3
- package/dist/index.d.mts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +7 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -17,6 +17,9 @@ function isInitOperation(operation) {
|
|
|
17
17
|
function isDraftOperation(operation) {
|
|
18
18
|
return "draftId" in operation;
|
|
19
19
|
}
|
|
20
|
+
function isEmptyBatchOperation(operation) {
|
|
21
|
+
return operation.type === "batch" && (operation.operations.length === 0 || operation.operations.every(isEmptyBatchOperation));
|
|
22
|
+
}
|
|
20
23
|
function flattenOperations(operations) {
|
|
21
24
|
return operations.flatMap((operation) => {
|
|
22
25
|
if (operation.type === "batch") {
|
|
@@ -25,6 +28,9 @@ function flattenOperations(operations) {
|
|
|
25
28
|
return operation;
|
|
26
29
|
});
|
|
27
30
|
}
|
|
31
|
+
function emptyOperation() {
|
|
32
|
+
return { type: "batch", operations: [] };
|
|
33
|
+
}
|
|
28
34
|
function buildResetOperation(previousDataMap, dataMap) {
|
|
29
35
|
const operations = [];
|
|
30
36
|
previousDataMap.forEach((_, id) => {
|
|
@@ -50,8 +56,10 @@ function getSymbol(name) {
|
|
|
50
56
|
exports.addBemModifier = addBemModifier;
|
|
51
57
|
exports.bem = bem;
|
|
52
58
|
exports.buildResetOperation = buildResetOperation;
|
|
59
|
+
exports.emptyOperation = emptyOperation;
|
|
53
60
|
exports.flattenOperations = flattenOperations;
|
|
54
61
|
exports.generateId = generateId;
|
|
55
62
|
exports.getSymbol = getSymbol;
|
|
56
63
|
exports.isDraftOperation = isDraftOperation;
|
|
64
|
+
exports.isEmptyBatchOperation = isEmptyBatchOperation;
|
|
57
65
|
exports.isInitOperation = isInitOperation;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IData,
|
|
1
|
+
import { IData, DataBatchOperation, DataOperation } from '@knotx/data';
|
|
2
2
|
|
|
3
3
|
declare function bem(block: string, element?: string, modifier?: string, prefix?: string): string;
|
|
4
4
|
declare function addBemModifier(className: string, modifier: string): string;
|
|
@@ -9,15 +9,23 @@ declare function addBemModifier(className: string, modifier: string): string;
|
|
|
9
9
|
*/
|
|
10
10
|
declare function generateId(): string;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
type DataInitBatchOperation<T extends IData> = DataBatchOperation<T> & {
|
|
13
|
+
isInit: true;
|
|
14
|
+
};
|
|
15
|
+
type DataEmptyBatchOperation<T extends IData> = DataBatchOperation<T> & {
|
|
16
|
+
operations: [] | DataEmptyBatchOperation<T>[];
|
|
17
|
+
};
|
|
18
|
+
declare function isInitOperation<T extends IData>(operation: DataOperation<T>): operation is DataInitBatchOperation<T>;
|
|
13
19
|
declare function isDraftOperation<T extends IData>(operation: DataOperation<T>): operation is Extract<DataOperation<T>, {
|
|
14
20
|
draftId: string;
|
|
15
21
|
}>;
|
|
22
|
+
declare function isEmptyBatchOperation<T extends IData>(operation: DataOperation<T>): operation is DataEmptyBatchOperation<T>;
|
|
16
23
|
declare function flattenOperations<T extends IData>(operations: DataOperation<T>[]): DataOperation<T>[];
|
|
24
|
+
declare function emptyOperation<T extends IData>(): DataEmptyBatchOperation<T>;
|
|
17
25
|
declare function buildResetOperation<T extends IData>(previousDataMap: Map<string, T>, dataMap: Map<string, T>): DataBatchOperation<T>;
|
|
18
26
|
|
|
19
27
|
declare function getSymbol<TName extends string>(name: TName): symbol & {
|
|
20
28
|
__knotx__?: TName;
|
|
21
29
|
};
|
|
22
30
|
|
|
23
|
-
export { addBemModifier, bem, buildResetOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
|
31
|
+
export { type DataEmptyBatchOperation, type DataInitBatchOperation, addBemModifier, bem, buildResetOperation, emptyOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isEmptyBatchOperation, isInitOperation };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IData,
|
|
1
|
+
import { IData, DataBatchOperation, DataOperation } from '@knotx/data';
|
|
2
2
|
|
|
3
3
|
declare function bem(block: string, element?: string, modifier?: string, prefix?: string): string;
|
|
4
4
|
declare function addBemModifier(className: string, modifier: string): string;
|
|
@@ -9,15 +9,23 @@ declare function addBemModifier(className: string, modifier: string): string;
|
|
|
9
9
|
*/
|
|
10
10
|
declare function generateId(): string;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
type DataInitBatchOperation<T extends IData> = DataBatchOperation<T> & {
|
|
13
|
+
isInit: true;
|
|
14
|
+
};
|
|
15
|
+
type DataEmptyBatchOperation<T extends IData> = DataBatchOperation<T> & {
|
|
16
|
+
operations: [] | DataEmptyBatchOperation<T>[];
|
|
17
|
+
};
|
|
18
|
+
declare function isInitOperation<T extends IData>(operation: DataOperation<T>): operation is DataInitBatchOperation<T>;
|
|
13
19
|
declare function isDraftOperation<T extends IData>(operation: DataOperation<T>): operation is Extract<DataOperation<T>, {
|
|
14
20
|
draftId: string;
|
|
15
21
|
}>;
|
|
22
|
+
declare function isEmptyBatchOperation<T extends IData>(operation: DataOperation<T>): operation is DataEmptyBatchOperation<T>;
|
|
16
23
|
declare function flattenOperations<T extends IData>(operations: DataOperation<T>[]): DataOperation<T>[];
|
|
24
|
+
declare function emptyOperation<T extends IData>(): DataEmptyBatchOperation<T>;
|
|
17
25
|
declare function buildResetOperation<T extends IData>(previousDataMap: Map<string, T>, dataMap: Map<string, T>): DataBatchOperation<T>;
|
|
18
26
|
|
|
19
27
|
declare function getSymbol<TName extends string>(name: TName): symbol & {
|
|
20
28
|
__knotx__?: TName;
|
|
21
29
|
};
|
|
22
30
|
|
|
23
|
-
export { addBemModifier, bem, buildResetOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
|
31
|
+
export { type DataEmptyBatchOperation, type DataInitBatchOperation, addBemModifier, bem, buildResetOperation, emptyOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isEmptyBatchOperation, isInitOperation };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IData,
|
|
1
|
+
import { IData, DataBatchOperation, DataOperation } from '@knotx/data';
|
|
2
2
|
|
|
3
3
|
declare function bem(block: string, element?: string, modifier?: string, prefix?: string): string;
|
|
4
4
|
declare function addBemModifier(className: string, modifier: string): string;
|
|
@@ -9,15 +9,23 @@ declare function addBemModifier(className: string, modifier: string): string;
|
|
|
9
9
|
*/
|
|
10
10
|
declare function generateId(): string;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
type DataInitBatchOperation<T extends IData> = DataBatchOperation<T> & {
|
|
13
|
+
isInit: true;
|
|
14
|
+
};
|
|
15
|
+
type DataEmptyBatchOperation<T extends IData> = DataBatchOperation<T> & {
|
|
16
|
+
operations: [] | DataEmptyBatchOperation<T>[];
|
|
17
|
+
};
|
|
18
|
+
declare function isInitOperation<T extends IData>(operation: DataOperation<T>): operation is DataInitBatchOperation<T>;
|
|
13
19
|
declare function isDraftOperation<T extends IData>(operation: DataOperation<T>): operation is Extract<DataOperation<T>, {
|
|
14
20
|
draftId: string;
|
|
15
21
|
}>;
|
|
22
|
+
declare function isEmptyBatchOperation<T extends IData>(operation: DataOperation<T>): operation is DataEmptyBatchOperation<T>;
|
|
16
23
|
declare function flattenOperations<T extends IData>(operations: DataOperation<T>[]): DataOperation<T>[];
|
|
24
|
+
declare function emptyOperation<T extends IData>(): DataEmptyBatchOperation<T>;
|
|
17
25
|
declare function buildResetOperation<T extends IData>(previousDataMap: Map<string, T>, dataMap: Map<string, T>): DataBatchOperation<T>;
|
|
18
26
|
|
|
19
27
|
declare function getSymbol<TName extends string>(name: TName): symbol & {
|
|
20
28
|
__knotx__?: TName;
|
|
21
29
|
};
|
|
22
30
|
|
|
23
|
-
export { addBemModifier, bem, buildResetOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
|
31
|
+
export { type DataEmptyBatchOperation, type DataInitBatchOperation, addBemModifier, bem, buildResetOperation, emptyOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isEmptyBatchOperation, isInitOperation };
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,9 @@ function isInitOperation(operation) {
|
|
|
15
15
|
function isDraftOperation(operation) {
|
|
16
16
|
return "draftId" in operation;
|
|
17
17
|
}
|
|
18
|
+
function isEmptyBatchOperation(operation) {
|
|
19
|
+
return operation.type === "batch" && (operation.operations.length === 0 || operation.operations.every(isEmptyBatchOperation));
|
|
20
|
+
}
|
|
18
21
|
function flattenOperations(operations) {
|
|
19
22
|
return operations.flatMap((operation) => {
|
|
20
23
|
if (operation.type === "batch") {
|
|
@@ -23,6 +26,9 @@ function flattenOperations(operations) {
|
|
|
23
26
|
return operation;
|
|
24
27
|
});
|
|
25
28
|
}
|
|
29
|
+
function emptyOperation() {
|
|
30
|
+
return { type: "batch", operations: [] };
|
|
31
|
+
}
|
|
26
32
|
function buildResetOperation(previousDataMap, dataMap) {
|
|
27
33
|
const operations = [];
|
|
28
34
|
previousDataMap.forEach((_, id) => {
|
|
@@ -45,4 +51,4 @@ function getSymbol(name) {
|
|
|
45
51
|
return Symbol.for(`knotx:${name}`);
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
export { addBemModifier, bem, buildResetOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
|
54
|
+
export { addBemModifier, bem, buildResetOperation, emptyOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isEmptyBatchOperation, isInitOperation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Utils for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@knotx/data": "0.2.
|
|
31
|
+
"@knotx/data": "0.2.9"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@knotx/build-config": "0.2.
|
|
35
|
-
"@knotx/eslint-config": "0.2.
|
|
36
|
-
"@knotx/typescript-config": "0.2.
|
|
34
|
+
"@knotx/build-config": "0.2.9",
|
|
35
|
+
"@knotx/eslint-config": "0.2.9",
|
|
36
|
+
"@knotx/typescript-config": "0.2.9"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "unbuild",
|