utils
utils 工具类方法集合。
方法列表
utils.clone(target)
typescript
(target: unknown) => unknown深度复制。
utils.merge(target, source)
typescript
(target: object, source: object) => void将一个对象合并到另一个对象。
utils.isString(value)
typescript
(value: unknown) => boolean检查某个值是否是字符串。
utils.isNumber(value)
typescript
(value: unknown) => boolean检查某个值是否是数字。
utils.isValid(value)
typescript
(value: unknown) => boolean检查某个值是否有效。
utils.isObject(value)
typescript
(value: unknown) => boolean检查某个值是否是对象。
utils.isFunction(value)
typescript
(value: unknown) => boolean检查某个值是否是方法。
utils.isBoolean(value)
typescript
(value: unknown) => boolean检查某个值是否是bool值。
utils.formatValue(value, key, defaultValue)
typescript
(data: unknown, key: string, defaultValue?: unknown) => unknown从某个值取对应的值,支持嵌套,如const o = { a: { b: { c: 1 } } },formatValue(o, 'a.b.c')取c的值。
utils.formatPrecision(value)
typescript
(value: string | number, precision?: number) => string格式化精度。
utils.formatBigNumber(value)
typescript
(value: string | number) => string格式化大的数字,如1000转换成1k,1000000转换为1M等。
utils.formatDate(dateTimeFormat, timestamp, format)
typescript
(dateTimeFormat: Intl.DateTimeFormat, timestamp: number, format: string) => string格式化日期。format格式,如'YYYY-MM-DD HH:mm:ss'。
utils.formatThousands(value, sign)
typescript
(value: string | number, sign: string) => string格式化千分符。
utils.formatFoldDecimal(value, threshold)
typescript
(value: string | number, threshold: number) => string格式化折叠小数。
utils.calcTextWidth(text, size, weight, family)
typescript
(text: string, size?: number, weight?: string | number, family?: string) => number计算文字宽度
utils.getLinearSlopeIntercept(coordinate1, coordinate2)
typescript
(
coordinate1: {
x: number
y: number
},
coordinate2: {
x: number
y: number
}
) => []根据两个坐标点,获取点组成的线的斜率和常数项,即y = kx + b中的k和b。
utils.getLinearYFromCoordinates(coordinate1, coordinate2, targetCoordinate)
typescript
(
coordinate1: {
x: number
y: number
},
coordinate2: {
x: number
y: number
}
targetCoordinate: {
x: number
y: number
}
) => number获取一个点在另外两个坐标点形成的线上的y轴坐标值。
utils.getLinearYFromSlopeIntercept(kb, targetCoordinate)
typescript
(
kb: Array<number>,
targetCoordinate: {
x: number
y: number
}
) => number获取一个点在斜率和常数项形成的线上的y轴坐标值。
utils.checkCoordinateOnArc(coordinate, arc)
typescript
(
coordinate: {
x: number
y: number
},
arc: {
x: number
y: number
r: number
startAngle: number
endAngle: number
}
) => boolean检查某个坐标点是否在圆弧上。
coordinate坐标点信息arc圆弧参数x圆心的x轴值y圆心的y轴值r半径startAngle起始角度endAngle结束角度
utils.checkCoordinateOnCircle(coordinate, circle)
typescript
(
coordinate: {
x: number
y: number
},
circle: {
x: number
y: number
r: number
}
) => boolean检查某个坐标点是否在圆上。
coordinate坐标点信息circle圆参数x圆心的x轴值y圆心的y轴值r半径
utils.checkCoordinateOnLine(coordinate, line)
typescript
(
coordinate: {
x: number
y: number
},
line: {
coordinates: Array<{
x: number
y: number
}>
}
) => boolean检查某个坐标点是否在线上。
utils.checkCoordinateOnPolygon(coordinate, polygon)
typescript
(
coordinate: {
x: number
y: number
},
polygon: {
coordinates: Array<{
x: number
y: number
}>
}
) => boolean检查某个坐标点是否在多边形上。
utils.checkCoordinateOnRect(coordinate, rect)
typescript
(
coordinate: {
x: number
y: number
},
rect: {
x: number
y: number
width: number
height: number
}
) => boolean检查某个坐标点是否在矩形上。
coordinate坐标点信息rect矩形参数x起始点x轴值y起始点y轴值width宽度height高度
utils.checkCoordinateOnText(coordinate, text, styles)
typescript
(
coordinate: {
x: number
y: number
},
text: {
x: number
y: number
text: unknown
align?: 'center' | 'end' | 'left' | 'right' | 'start'
baseline?: 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top'
},
styles: {
color?: string
size?: number
family?: string
weight?: number | string
}
) => boolean检查某个坐标点是否在文字上。
coordinate坐标点信息text文字参数x起始点x轴值y起始点y轴值text文字内容align水平对齐方式baseline垂直对齐方式
styles样式color颜色size尺寸family字体weight权重