Utils
Type module
Sources
Items from Utils can be imported/included and used via following ways.
/** * Import via main package * Access items like: am4core.utils.myVariable */import * as am4core from "@amcharts/amcharts4";
/** * Import via: Utils.ts * Access items like: $utils.myVariable */import * as $utils from "@amcharts/amcharts4/Utils";/** * Include via "core.js" * Access items like: am4core.utils.myVariable */Variables
urlRegexpType
RegExpDefault/^([a-zA-Z][a-zA-Z0-9+.-]*:)?(?:(//)([^@]+@)?([^/?#:]*)(:[0-9]+)?)?([^?#]*)(?[^#]*)?(#.*)?$/
Functions
anyToDate(value:Date|number|string)Returns
DateConverts anything to Date object.
anyToNumber(value:Date|number|string)Returns
$type.Optional<number>Tries converting any value to a number.
camelToDashed(str:string)Returns
stringConverts camelCased text to dashed version:
("thisIsString" > "this-is-string")
capitalize(str:string)Returns
stringConverts tring to uppercase.
copyProperties(source:object,
target:object,
keys:Array<string>)Returns
voidCopies all properties of one object to the other, omitting undefined.
documentPointToSprite(point:IPoint,
sprite:Sprite)Returns
IPointConverts document-wide global coordinates to coordinates within specific
Sprite.documentPointToSvg(point:IPoint,
svgContainer:HTMLElement,
cssScale?:number)Returns
IPointConverts global document-wide coordinates to coordinates within SVG element.
escapeForRgex(value:string)Returns
stringEscapes string so it can safely be used in a Regex.
fitNumber(value:number,
min:number,
max:number)Returns
numberFits the number into specific
minandmaxbounds.fitNumberRelative(value:number,
min:number,
max:number)Returns
numberFits the number into specific
minandmaxbounds.If the value is does not fit withing specified range, it "wraps" around the values.
For example, if we have input value 10 with min set at 1 and max set at 8, the value will not fit. The remainder that does not fit (2) will be added to
min, resulting in 3.The output of regular
fitNumber()would return 8 instead.get12Hours(hours:number,
base?:number)Returns
numberReturns 12-hour representation out of the 24-hour hours.
getBaseURI()Returns
stringgetDayFromWeek(week:number,
year:number,
weekday:number,
utc:boolean)Returns
numberReturns a year day out of the given week number.
getMonthWeek(date:Date,
utc:boolean)Returns
numberReturns a week number in the month.
getPixelRatio()Returns
numberReturns pixel ratio of the current screen (used on retina displays).
getTimeZone(date:Date,
long:boolean,
savings:boolean,
utc:boolean)Returns
stringReturns a string name of the tome zone.
getWeek(date:Date,
utc:boolean)Returns
numberReturns week number for a given date.
getYearDay(date:Date,
utc:boolean)Returns
numberReturns a year day.
isIE()Returns
booleanDetects MSIE.
isNotEmpty(value:$type.Optional<string>)Returns
valueChecks if value is not empty (undefined or zero-length string).
ltrim(str:string)Returns
stringRemoves whitespace from beginning of the string.
numberToString(value:number)Returns
stringConverts numeric value into string. Deals with large or small numbers that would otherwise use exponents.
padString(value:any,
len:number,
char:string)Returns
stringPads a string with additional characters to certain length.
plainText(text:string)Returns
stringRemoves new lines and tags from a string.
random(chars:number)Returns
stringReturns a random number between
fromandto.reverseString(str:string)Returns
stringReverses string.
rtrim(str:string)Returns
stringRemoves whitespace from end of the string.
softCopyProperties(source:object,
target:object,
keys:Array<string>)Returns
voidCopies all properties of one object to the other, omitting undefined, but only if property in target object doesn't have a value set.
splitTextByCharCount(text:string,
maxChars:number,
fullWords?:boolean,
rtl?:boolean,
fullWordFallback?:boolean)Returns
string[]Splits the text into multiple lines, respecting maximum character count.
Prioretizes splitting on spaces and punctuation. Falls back on splitting mid-word if there's no other option.
spritePointToDocument(point:IPoint,
sprite:Sprite)Returns
IPointConverts coordinates within
Spriteto global document coordinates.spritePointToSprite(point:IPoint,
sprite:Sprite,
toSprite:Sprite)Returns
IPointConverts coordinates of one sprite to another.
spritePointToSvg(point:IPoint,
sprite:Sprite)Returns
IPointConverts coordinates within
Spriteto coordinates relative to the whole SVG element.spriteRectToSvg(rect:IRectangle,
sprite:Sprite)Returns
IRectangleConverts a rectangle expressed in
Spritecoordinates to SVG coordinates.stringify(value:any)Returns
stringConverts any value into its string representation.
stripHash(url:string)Returns
stringRemoves target from url
stripTags(text:string)Returns
stringStrips all tags from the string.
svgPointToDocument(point:IPoint,
svgContainer:HTMLElement)Returns
IPointConverts SVG coordinates to global document-wide coordinates.
svgPointToSprite(point:IPoint,
sprite:Sprite)Returns
IPointConverts SVG element coordinates to coordinates within specific
Sprite.svgRectToSprite(rect:IRectangle,
sprite:Sprite)Returns
IRectangleConverts a rectangle expressed in SVG element coordinates to coordinates within specific
Sprite.trim(str:string)Returns
stringRemoves whitespace from beginning and end of the string.
truncateWithEllipsis(text:string,
maxChars:number,
ellipsis:string,
fullWords?:boolean,
rtl?:boolean)Returns
stringTruncates the text to certain character count.
Will add ellipsis if the string is truncated. Optionally, can truncate on full words only.
For RTL support, pass in the fifth parameter as
true.unquote(str:string)Returns
stringRemoves quotes from the string.
used(value:A)Returns
voidMarks a value as being used (e.g. because the value has side effects).