增加 money 和 mask
This commit is contained in:
parent
42fca4aa3f
commit
02f253f591
|
|
@ -1,5 +1,6 @@
|
|||
import { RecurrenceRule, RecurrenceSpecDateRange, RecurrenceSpecObjLit } from 'node-schedule';
|
||||
import { EntityDict } from './Entity';
|
||||
import { AsyncContext } from "../store/AsyncRowStore";
|
||||
import { AsyncContext } from '../store/AsyncRowStore';
|
||||
declare type RoutineFn<ED extends EntityDict, Cxt extends AsyncContext<ED>> = (context: Cxt) => Promise<string>;
|
||||
export declare type Routine<ED extends EntityDict, Cxt extends AsyncContext<ED>> = {
|
||||
name: string;
|
||||
|
|
@ -7,7 +8,7 @@ export declare type Routine<ED extends EntityDict, Cxt extends AsyncContext<ED>>
|
|||
};
|
||||
export declare type Timer<ED extends EntityDict, Cxt extends AsyncContext<ED>> = {
|
||||
name: string;
|
||||
cron: string;
|
||||
cron: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number;
|
||||
fn: RoutineFn<ED, Cxt>;
|
||||
};
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
export declare function schedule(cron: string, fn: (date: Date) => any): void;
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.schedule = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var cronjs_matcher_1 = require("@datasert/cronjs-matcher");
|
||||
var dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
||||
function schedule(cron, fn) {
|
||||
var futureMatches = (0, cronjs_matcher_1.getFutureMatches)(cron, {
|
||||
matchCount: 1,
|
||||
});
|
||||
var date = (0, dayjs_1.default)(futureMatches[0]);
|
||||
var interval = date.diff((0, dayjs_1.default)(), 'ms');
|
||||
setTimeout(function () {
|
||||
fn(new Date());
|
||||
schedule(cron, fn);
|
||||
}, interval);
|
||||
}
|
||||
exports.schedule = schedule;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
declare const maskIdCard: (idCardNumber: string) => string;
|
||||
declare const maskMobile: (mobile: string) => string;
|
||||
declare const maskName: (name: string) => string;
|
||||
declare const maskStar: (str: string, front: number, end: number, star: string) => string;
|
||||
export { maskIdCard, maskMobile, maskName, maskStar, };
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.maskStar = exports.maskName = exports.maskMobile = exports.maskIdCard = void 0;
|
||||
var maskIdCard = function (idCardNumber) {
|
||||
if (!idCardNumber instanceof String) {
|
||||
throw new Error("身份证号码必须是String类型");
|
||||
}
|
||||
var begin = idCardNumber.slice(0, 4);
|
||||
var end = idCardNumber.slice(idCardNumber.length - 4, 4);
|
||||
for (var i = 0; i < idCardNumber.length - 8; i++) {
|
||||
begin = begin.concat("*");
|
||||
}
|
||||
return begin.concat(end);
|
||||
};
|
||||
exports.maskIdCard = maskIdCard;
|
||||
var maskMobile = function (mobile) {
|
||||
var begin = mobile.slice(0, 3);
|
||||
var end = mobile.slice(7, 11);
|
||||
return begin.concat("****").concat(end);
|
||||
};
|
||||
exports.maskMobile = maskMobile;
|
||||
var maskName = function (name) {
|
||||
return name.slice(0, name.length - 1).concat("*");
|
||||
};
|
||||
exports.maskName = maskName;
|
||||
var maskStar = function (str, frontLen, endLen, star) {
|
||||
if (star === void 0) { star = '*'; }
|
||||
var len = str.length - frontLen - endLen;
|
||||
var xing = '';
|
||||
for (var i = 0; i < len; i++) {
|
||||
xing += star;
|
||||
}
|
||||
return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
|
||||
};
|
||||
exports.maskStar = maskStar;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
declare const ToCent: (float: number) => number;
|
||||
declare const ToYuan: (int: number) => number;
|
||||
declare const StringToCent: (value: string, allowNegative?: true) => number | undefined;
|
||||
declare const CentToString: (value: number) => string | undefined;
|
||||
export { ToCent, ToYuan, StringToCent, CentToString, };
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CentToString = exports.StringToCent = exports.ToYuan = exports.ToCent = void 0;
|
||||
var ToCent = function (float) {
|
||||
return Math.round(float * 100);
|
||||
};
|
||||
exports.ToCent = ToCent;
|
||||
var ToYuan = function (int) {
|
||||
return Math.round(int) / 100;
|
||||
};
|
||||
exports.ToYuan = ToYuan;
|
||||
var StringToCent = function (value, allowNegative) {
|
||||
var numValue = parseInt(value, 10);
|
||||
if (typeof numValue === 'number' && (numValue >= 0 || allowNegative)) {
|
||||
return ToCent(numValue);
|
||||
}
|
||||
};
|
||||
exports.StringToCent = StringToCent;
|
||||
var CentToString = function (value) {
|
||||
if (typeof value === 'number') {
|
||||
return "".concat(ToYuan(value));
|
||||
}
|
||||
};
|
||||
exports.CentToString = CentToString;
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
"@types/luxon": "^2.0.9",
|
||||
"@types/mocha": "^8.2.0",
|
||||
"@types/node": "^14.14.25",
|
||||
"@types/node-schedule": "^2.1.0",
|
||||
"@types/react": "^17.0.2",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@types/wechat-miniprogram": "^3.4.1",
|
||||
|
|
@ -40,9 +41,9 @@
|
|||
"typescript": "^4.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@datasert/cronjs-matcher": "^1.2.0",
|
||||
"dayjs": "^1.11.5",
|
||||
"lodash": "^4.17.21",
|
||||
"node-schedule": "^2.1.1",
|
||||
"uuid": "^9.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
import { RecurrenceRule, RecurrenceSpecDateRange, RecurrenceSpecObjLit } from 'node-schedule';
|
||||
import { EntityDict } from './Entity';
|
||||
import { AsyncContext } from "../store/AsyncRowStore";
|
||||
import { AsyncContext } from '../store/AsyncRowStore';
|
||||
|
||||
type RoutineFn<ED extends EntityDict, Cxt extends AsyncContext<ED>> = (context: Cxt) => Promise<string>;
|
||||
type RoutineFn<ED extends EntityDict, Cxt extends AsyncContext<ED>> = (
|
||||
context: Cxt
|
||||
) => Promise<string>;
|
||||
|
||||
export type Routine<ED extends EntityDict, Cxt extends AsyncContext<ED>> = {
|
||||
name: string;
|
||||
|
|
@ -10,6 +13,6 @@ export type Routine<ED extends EntityDict, Cxt extends AsyncContext<ED>> = {
|
|||
|
||||
export type Timer<ED extends EntityDict, Cxt extends AsyncContext<ED>> = {
|
||||
name: string;
|
||||
cron: string;
|
||||
cron: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number;
|
||||
fn: RoutineFn<ED, Cxt>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
import { getFutureMatches } from '@datasert/cronjs-matcher';
|
||||
import DayJs from 'dayjs';
|
||||
|
||||
export function schedule(cron: string, fn: (date: Date) => any) {
|
||||
const futureMatches = getFutureMatches(cron, {
|
||||
matchCount: 1,
|
||||
});
|
||||
const date = DayJs(futureMatches[0]);
|
||||
const interval = date.diff(DayJs(), 'ms');
|
||||
setTimeout(
|
||||
() => {
|
||||
fn(new Date());
|
||||
schedule(cron, fn);
|
||||
},
|
||||
interval
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
const maskIdCard: (idCardNumber: string) => string = (idCardNumber) => {
|
||||
if(!idCardNumber as any instanceof String) {
|
||||
throw new Error("身份证号码必须是String类型");
|
||||
}
|
||||
let begin = idCardNumber.slice(0, 4);
|
||||
let end = idCardNumber.slice(idCardNumber.length - 4, 4);
|
||||
for(let i = 0; i < idCardNumber.length - 8; i ++) {
|
||||
begin = begin.concat("*");
|
||||
}
|
||||
return begin.concat(end);
|
||||
}
|
||||
|
||||
const maskMobile: (mobile: string) => string = (mobile) => {
|
||||
let begin = mobile.slice(0, 3);
|
||||
let end = mobile.slice(7, 11);
|
||||
return begin.concat("****").concat(end);
|
||||
}
|
||||
|
||||
|
||||
const maskName: (name: string) => string = (name) => {
|
||||
return name.slice(0, name.length - 1).concat("*");
|
||||
}
|
||||
|
||||
const maskStar: (str: string, front: number, end: number, star: string) => string = (str, frontLen, endLen, star = '*') => {
|
||||
const len = str.length - frontLen - endLen;
|
||||
let xing = '';
|
||||
for (let i = 0; i < len; i++) {
|
||||
xing += star;
|
||||
}
|
||||
return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export {
|
||||
maskIdCard,
|
||||
maskMobile,
|
||||
maskName,
|
||||
maskStar,
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
const ToCent: (float: number) => number = (float) => {
|
||||
return Math.round(float * 100);
|
||||
}
|
||||
|
||||
const ToYuan: (int: number) => number = ( int) => {
|
||||
return Math.round(int) / 100;
|
||||
}
|
||||
|
||||
const StringToCent: (value: string, allowNegative?: true) => number | undefined = (value, allowNegative) => {
|
||||
const numValue = parseInt(value, 10);
|
||||
if (typeof numValue === 'number' && (numValue >= 0 || allowNegative)) {
|
||||
return ToCent(numValue);
|
||||
}
|
||||
}
|
||||
|
||||
const CentToString: (value: number) => string | undefined = (value) => {
|
||||
if (typeof value === 'number') {
|
||||
return `${ToYuan(value)}`;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
ToCent,
|
||||
ToYuan,
|
||||
StringToCent,
|
||||
CentToString,
|
||||
}
|
||||
Loading…
Reference in New Issue