Skip to content

Commit

Permalink
chore: eslint format
Browse files Browse the repository at this point in the history
  • Loading branch information
fupengl committed Sep 4, 2021
1 parent 1f9f583 commit 8082850
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/array/array-to-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ function arrayToTree<
T extends Dictionary<any>,
K extends string,
Opts extends ArrayToTreeOption<T, K> = ArrayToTreeOption<T, K>,
Node = TreeNode<T, NonNullable<Opts['childrenKey']>>
Node = TreeNode<T, NonNullable<Opts['childrenKey']>>,
>(array: T[], option?: Opts): Record<string, Node> {
const { parentPrimaryKey = 'parentId', primaryKey = 'id', childrenKey = 'children' } =
option || {};
const {
parentPrimaryKey = 'parentId',
primaryKey = 'id',
childrenKey = 'children',
} = option || {};
const hasOwnProperty = Object.prototype.hasOwnProperty;
return array.reduce<Record<string, Node>>((branches, node) => {
const parentId = node[parentPrimaryKey];
Expand Down
2 changes: 1 addition & 1 deletion src/array/map-pick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function mapPick<
T extends Dictionary<any>,
K extends string,
Value = T[keyof T],
Item = Record<K, Value>
Item = Record<K, Value>,
>(
array: readonly T[],
keyPaths?: Record<K, (PropertyPath | keyof T)[]>,
Expand Down
8 changes: 4 additions & 4 deletions src/function/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ function set<Entity = any, Output = Entity, Value = any>(
value: Value,
): Output {
if (!paths.length) {
return (value as unknown) as Output;
return value as unknown as Output;
}

const [path, ...restPath] = paths;

let clone: Output;
if (!entity && typeof path === 'number') {
clone = ([] as unknown) as Output;
clone = [] as unknown as Output;
} else if (Array.isArray(entity)) {
clone = ([...entity] as unknown) as Output;
clone = [...entity] as unknown as Output;
} else {
clone = ({ ...entity } as unknown) as Output;
clone = { ...entity } as unknown as Output;
}

clone[path as string] = set(clone[path as string], restPath, value);
Expand Down
21 changes: 14 additions & 7 deletions src/regex_constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const REG_IMEI = /^\d{15,17}$/;
* 身份证号, 支持1/2代(15位/18位数字)
* @category RegExp
*/
export const REG_ID_CARD = /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0[1-9]|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/;
export const REG_ID_CARD =
/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0[1-9]|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/;

/**
* 必须带端口号的网址(或ip)
Expand Down Expand Up @@ -56,7 +57,8 @@ export const REG_URI = new RegExp(
* 子网掩码
* @category RegExp
*/
export const REG_SUBNET_MASK = /^(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/;
export const REG_SUBNET_MASK =
/^(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/;

/**
* md5 32
Expand Down Expand Up @@ -119,7 +121,8 @@ export const REG_EN_NAME = /(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/;
* 统一社会信用代码
* @category RegExp
*/
export const REG_UNIFIED_SOCIAL_CREDIT_CODE = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
export const REG_UNIFIED_SOCIAL_CREDIT_CODE =
/^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;

/**
* 小数
Expand All @@ -143,13 +146,15 @@ export const REG_ENGLISH = /^[a-zA-Z]+$/;
* ip-v4
* @category RegExp
*/
export const REG_IPV4 = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
export const REG_IPV4 =
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;

/**
* ip-v6
* @category RegExp
*/
export const REG_IPV6 = /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i;
export const REG_IPV6 =
/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i;

/**
* 16进制颜色
Expand All @@ -161,13 +166,15 @@ export const REG_HEX_COLOR = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
* 颜色16进制颜色,rgb或rgba
* @category RegExp
*/
export const REG_COLOR = /^(#([0-9a-fA-F]{3}){1,2}|[rR][gG][Bb](\((\s*(2[0-4]\d|25[0-5]|[01]?\d{1,2})\s*,){2}\s*(2[0-4]\d|25[0-5]|[01]?\d{1,2})\s*\)|[Aa]\((\s*(2[0-4]\d|25[0-5]|[01]?\d{1,2})\s*,){3}\s*([01]|0\.\d+)\s*\)))$/;
export const REG_COLOR =
/^(#([0-9a-fA-F]{3}){1,2}|[rR][gG][Bb](\((\s*(2[0-4]\d|25[0-5]|[01]?\d{1,2})\s*,){2}\s*(2[0-4]\d|25[0-5]|[01]?\d{1,2})\s*\)|[Aa]\((\s*(2[0-4]\d|25[0-5]|[01]?\d{1,2})\s*,){3}\s*([01]|0\.\d+)\s*\)))$/;

/**
* 邮政编码(中国)
* @category RegExp
*/
export const REG_POSTAL_CODEi = /^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/;
export const REG_POSTAL_CODEi =
/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/;

/**
* 判断是否是base64
Expand Down

0 comments on commit 8082850

Please sign in to comment.