wip: code review

This commit is contained in:
元凛
2022-02-09 10:08:44 +08:00
parent f79ccb5f94
commit 8cd9c11d81
19 changed files with 7849 additions and 3136 deletions

View File

View File

@@ -1,10 +0,0 @@
import sampleSize from 'lodash/sampleSize';
import { dealStringToArr } from 'actions-util';
export const dealRandomAssignees = (assignees: string, randomTo: string | void): string[] => {
let arr = dealStringToArr(assignees);
if (randomTo && Number(randomTo) > 0 && Number(randomTo) < arr.length) {
arr = sampleSize(arr, Number(randomTo));
}
return arr;
}

View File

@@ -1,5 +1,31 @@
import { dealStringToArr } from 'actions-util';
export { dealStringToArr };
import sampleSize from 'lodash/sampleSize';
export * from './data';
export * from './deal';
export const dealRandomAssignees = (assignees: string, randomTo: string | void): string[] => {
let arr = dealStringToArr(assignees);
if (randomTo && Number(randomTo) > 0 && Number(randomTo) < arr.length) {
arr = sampleSize(arr, Number(randomTo));
}
return arr;
}
export const matchKeyword = (content: string, keywords: string[]): boolean => {
return !!keywords.find(item => content.toLowerCase().includes(item));
}
export const checkDuplicate = (body: string | void): boolean => {
if (!body || !body.startsWith('Duplicate of')) {
return false;
}
const arr = body.split(' ');
return arr[0] == 'Duplicate' && arr[1] == 'of'
}
export const getPreMonth = (m: number): number => {
return m == 1 ? 12 : m - 1;
}
// replace some & split & cull empty
export const replaceStr2Arr = (str: string, replace: string, split: string): string[] => {
return str.replace(replace, '').trim().split(split).reduce((result: string[], it) => it ? [...result, it.trim()] : result, []);
}