Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mini256 committed Jan 15, 2021
1 parent 967091d commit b944aa2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/utils/parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
type label =
| string
| {
id?: number;
name?: string;
};

/**
* Convert the comma string to array.
* @param str Label string separated by commas, e.g. "type/feature,status/can-merge".
Expand All @@ -9,18 +16,17 @@ export function decodeLabelString(str: string): string[] {

/**
* Convert an array to a string that separates array items by commas.
* @param arr A label string array, e.g. ["type/feature", "status/can-merge"].
* @param labelArr
* @return Label string, e.g. "type/feature,status/can-merge".
*/
export function encodeLabelArray(
arr: {
id?: number;
name?: string;
}[]
): string {
return arr
export function encodeLabelArray(labelArr: label[]): string {
return labelArr
.map((label) => {
return label.name?.trim();
if (typeof label === "string") {
return label;
} else {
return label.name?.trim();
}
})
.join(",");
}
7 changes: 7 additions & 0 deletions src/utils/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
let scheduler = typeof setImmediate === "function" ? setImmediate : setTimeout;

/**
* Flush all pending resolved promise handlers. Useful in tests.
* Usage:
* ```
* await flushPromises();
* ```
*/
export function flushPromises() {
return new Promise(function (resolve) {
scheduler(resolve, 0);
Expand Down

0 comments on commit b944aa2

Please sign in to comment.