mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-10-15 08:13:48 +08:00
wip: code review
This commit is contained in:
@@ -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;
|
||||
}
|
@@ -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, []);
|
||||
}
|
||||
|
Reference in New Issue
Block a user