utils
utils collection of tool class methods.
Method List
utils.clone(target)
(target: any) => anydeep copy.
utils.merge(target, source)
(target: object, source: object) => voidMerge one object into another.
utils.isString(value)
(value: any) => booleanChecks if a value is a string.
utils.isNumber(value)
(value: any) => booleanChecks if a value is a number.
utils.isValid(value)
(value: any) => booleanChecks if a value is valid.
utils.isObject(value)
(value: any) => booleanChecks if a value is an object.
utils.isFunction(value)
(value: any) => booleanChecks if a value is a method.
utils.isBoolean(value)
(value: any) => booleanChecks if a value is a bool value.
utils.formatValue(value, key, defaultValue)
(data: any, key: string, defaultValue?: any) => anyGet the corresponding value from a certain value, support nesting, such as const o = { a: { b: { c: 1 } } }, formatValue(o, 'a.b.c') takes the value of c .
utils.formatPrecision(value)
(value: string | number, precision?: number) => stringFormatting precision.
utils.formatBigNumber(value)
(value: string | number) => stringFormat large numbers, such as 1000 into 1k, 1000000 into 1M, etc.
utils.formatDate(dateTimeFormat, timestamp, format)
(dateTimeFormat: Intl.DateTimeFormat, timestamp: number, format: string) => stringFormat date. format, such as 'YYYY-MM-DD HH:mm:ss'.
utils.formatThousands(value, sign)
(value: string | number, sign: string) => stringFormat thousands separator.
utils.formatFoldDecimal(value, threshold) ^9.8.0
(value: string | number, threshold: number) => stringFormat fold decimal.
utils.calcTextWidth(text, size, weight, family) ^9.3.0
(text: string, size?: number, weight?: string | number, family?: string) => numberCalculate text width.
utils.getLinearSlopeIntercept(coordinate1, coordinate2)
(
coordinate1: {
x: number
y: number
},
coordinate2: {
x: number
y: number
}
) => []According to two coordinate points, get the slope and constant term of the line composed of points, namely k and b in y = kx + b.
utils.getLinearYFromCoordinates(coordinate1, coordinate2, targetCoordinate)
(
coordinate1: {
x: number
y: number
},
coordinate2: {
x: number
y: number
},
targetCoordinate: {
x: number
y: number
}
) => numberGet the y-axis coordinate value of a point on the line formed by two other coordinate points.
utils.getLinearYFromSlopeIntercept(kb, targetCoordinate)
(
kb: Array<number>,
targetCoordinate: {
x: number
y: number
}
) => numberGet the y-coordinate value of a point on the line formed by the slope and the constant term.
utils.checkCoordinateOnArc(coordinate, arc)
(
coordinate: {
x: number
y: number
},
arc: {
x: number
y: number
r: number
startAngle: number
endAngle: number
}
) => booleanCheck whether a certain coordinate point is on the arc.
coordinatecoordinate point informationarcarc parameterxthe x-axis value of the center of the circleythe y-axis value of the center of the circlerradiusstartAnglestart angleendAngleend angle
utils.checkCoordinateOnCircle(coordinate, circle)
(
coordinate: {
x: number
y: number
},
circle: {
x: number
y: number
r: number
}
) => booleanChecks whether a certain coordinate point is on a circle.
coordinatecoordinate point informationcirclecircle parameterxthe x-axis value of the center of the circleythe y-axis value of the center of the circlerradius
utils.checkCoordinateOnLine(coordinate, line)
(
coordinate: {
x: number
y: number
},
line: {
coordinates: Array<{
x: number
y: number
}>
}
) => booleanCheck if a certain coordinate point is on the line.
utils.checkCoordinateOnPolygon(coordinate, polygon)
(
coordinate: {
x: number
y: number
},
polygon: {
coordinates: Array<{
x: number
y: number
}>
}
) => booleanChecks whether a certain coordinate point is on a polygon.
utils.checkCoordinateOnRect(coordinate, rect)
(
coordinate: {
x: number
y: number
},
rect: {
x: number
y: number
width: number
height: number
}
) => booleanChecks whether a certain coordinate point is on a rectangle.
coordinatecoordinate point informationrectrectangle parameterxstarting point x-axis valueystarting point y-axis valuewidthwidthheightheight
utils.checkCoordinateOnText(coordinate, text, styles)
(
coordinate: {
x: number
y: number
},
text: {
x: number
y: number
text: any
align?: 'center' | 'end' | 'left' | 'right' | 'start'
baseline?: 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top'
},
styles: {
color?: string
size?: number
family?: string
weight?: number | string
}
) => booleanCheck if a certain coordinate point is on the text.
coordinatecoordinate point informationtexttext parameterxstarting point x-axis valueystarting point y-axis valuetexttext contentalignhorizontal alignmentbaselinevertical alignment
stylesstylescolorcolorsizesizefamilyfontweightweight