utils â
utils
collection of tool class methods.
Method List â
utils.clone(target) â
(target: any) => any
deep copy.
utils.merge(target, source) â
(target: object, source: object) => void
Merge one object into another.
utils.isString(value) â
(value: any) => boolean
Checks if a value is a string.
utils.isNumber(value) â
(value: any) => boolean
Checks if a value is a number.
utils.isValid(value) â
(value: any) => boolean
Checks if a value is valid.
utils.isObject(value) â
(value: any) => boolean
Checks if a value is an object.
utils.isFunction(value) â
(value: any) => boolean
Checks if a value is a method.
utils.isBoolean(value) â
(value: any) => boolean
Checks if a value is a bool value.
utils.formatValue(value, key, defaultValue) â
(data: any, key: string, defaultValue?: any) => any
Get 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) => string
Formatting precision.
utils.formatBigNumber(value) â
(value: string | number) => string
Format large numbers, such as 1000 into 1k, 1000000 into 1M, etc.
utils.formatDate(dateTimeFormat, timestamp, format) â
(dateTimeFormat: Intl.DateTimeFormat, timestamp: number, format: string) => string
Format date. format
, such as 'YYYY-MM-DD HH:mm:ss'.
utils.formatThousands(value, sign) â
(value: string | number, sign: string) => string
Format thousands separator.
utils.formatFoldDecimal(value, threshold) ^9.8.0 â
(value: string | number, threshold: number) => string
Format fold decimal.
utils.calcTextWidth(text, size, weight, family) ^9.3.0 â
(text: string, size?: number, weight?: string | number, family?: string) => number
Calculate 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
}
) => number
Get 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
}
) => number
Get 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
}
) => boolean
Check whether a certain coordinate point is on the arc.
coordinate
coordinate point informationarc
arc parameterx
the x-axis value of the center of the circley
the y-axis value of the center of the circler
radiusstartAngle
start angleendAngle
end angle
utils.checkCoordinateOnCircle(coordinate, circle) â
(
coordinate: {
x: number
y: number
},
circle: {
x: number
y: number
r: number
}
) => boolean
Checks whether a certain coordinate point is on a circle.
coordinate
coordinate point informationcircle
circle parameterx
the x-axis value of the center of the circley
the y-axis value of the center of the circler
radius
utils.checkCoordinateOnLine(coordinate, line) â
(
coordinate: {
x: number
y: number
},
line: {
coordinates: Array<{
x: number
y: number
}>
}
) => boolean
Check 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
}>
}
) => boolean
Checks 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
}
) => boolean
Checks whether a certain coordinate point is on a rectangle.
coordinate
coordinate point informationrect
rectangle parameterx
starting point x-axis valuey
starting point y-axis valuewidth
widthheight
height
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
}
) => boolean
Check if a certain coordinate point is on the text.
coordinate
coordinate point informationtext
text parameterx
starting point x-axis valuey
starting point y-axis valuetext
text contentalign
horizontal alignmentbaseline
vertical alignment
styles
stylescolor
colorsize
sizefamily
fontweight
weight