npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@viiksetjs/utils

v1.1.6-alpha.0

Published

This library contains useful functions for manipulating data for data visualizations. It does not necessarily have to be used in conjunction with [@viiksetjs/web](https://github.com/jamestthompson3/viiksetjs/blob/master/packages/web/README.md) Some of the

Readme

@viiksetjs/utils

This library contains useful functions for manipulating data for data visualizations. It does not necessarily have to be used in conjunction with @viiksetjs/web Some of these functions are used in building the default assumptions for @viiksetjs/web charts, and may or may not be useful own their own.

Exported Functions

| Function Name | Signature | Desc | | :------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | parseIfDate | (data: any): Date \| undefined | takes any piece of data and tries to convert it into instance of Date. Returns undefined if the conversion fails | | parseObject | <T>(obj: Object, arg: string, applicator: (obj) => any): T[] | takes and object, a typeof argument, and an applicator function. It will map through the object's values with the applicator, then filter the results according to the typeof argument | | getX | (data: GenericData[], xKey?: string): any[] | takes an array of data objects and optionally an xKey and returns the xKey points for each object in the data array, or tries to parse a date from each object. Example: getX([{messages: 123, users: 133}, {messages: 100, users: 33}, 'messages']) would return: [123, 100, ...] | | getY | (data: GenericData[], yKey?: string): any[] | same as getX except it tries to fall back to a number instead of trying to parse a Date. Example: getY([{messages: 123, date: '11-10-2018'},{messages: 100, date: '08-10-2018'}, ...]) would result in [123, 100,...] | | extractX | (datum: Object, xKey?: string, type: string): any[] | similar to getX, but instead of taking an array of data objects, it takes a single data object and extracts all x values from that object | | extractY | (datum: Object, xKey?: string): any[] | same as extractX, but with y values | | extractLabels | (datum: Object): string[] | takes a data object and extracts the y labels by parsing which values contain numbers | | createLinearScales | (data: GenericData[], dataKeys: string[], height: number, margin: Margin ): ScalarObject | creates a vertical linear scale for each of the data keys found in the array of data objects. Example: createLinearScales([{messages: 123, users: 333}, ...], ['messages', 'users'], 400, {top: 10, bottom: 10, left: 10, right: 10}) would result in: {messages: scaleFunctionForMessages, users: scaleFunctionForUsers} | | formatTime | (d: string): string | default time formatter for viiksetjs, returns dates in the following format: Mon Jan 19 (ddd mmm DD) | | tooltipTime | (d: string): string | default time format for tooltips, returns time in this format: Sun Jan 21st 20:29 (ddd mmm DD HH:MM) | | formatTicks | (d: string \| number): string | default tick formatter, if it the argument is a number, it will return ${arg}k if the argument is over 1000, else it just returns the argument | | formatXTicks | (d: string \| Date \| number): string \| number | returns the default date format if the argument passed is a valid date, otherwise, just returns what it was given | | determineXScale | (type: 'ordinal'\|'linear', xPoints: number[]\|Date[]\|string[], orientation?: 'horizontal', margin: Margin, width: number): ScaleFunction | returns a horizontal scale based on the type of chart, width, and margin | | determineYScale | (type: 'ordinal'\|'linear', orientation?: 'horizontal', yPoints: number[]\|string[], height: number, margin: Margin ): ScaleFunction | returns a vertical scale based on the type of chart, height, and margin | | findTooltipX | (calculatedX: any, xScale: ScaleFunction): number | takes a calculated x value and returns its position in the chart based on the given xScale | | prepChartData | (size: Size, xKey?: string, yKey?: string, type: 'ordinal'\|'linear', margin: Margin, data: GenericData[], orientation?: 'horizontal'): Promise<State> | prepares x and y scales, calculates chart height and width, xPoints, yPoints, and datakeys | | interpolateColors | (a: string, b: string, amount: number): string | interpolates between the given 2 numbers to get, for example, the color in between the two. Amount is a range from 0.0 - 1.1 |

Exported Types and Interfaces

| Interface Name | Signature | Desc | | :-------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------- | | ScaleProps | { type: string; xPoints: number[] \| string[] \| Date[]; yPoints: number[] \| string[]; width: number; invertedRange: boolean; height: number; orientation: string;margin: Margin; } | props passed to scale functions as Partial<ScaleProps> | | ScaleFunction | ScaleBand<R> \| ScaleContinuousNumeric<R, O> \| ScaleLinear<R, O> \| ScaleTime<R, O> \| ScaleOrdinal<R, O> | represents the different scale functions in viiksetjs | | Margin | { left: number; right: number; top: number; bottom: number; } | margin for chart areas | | Size | { width: number; height: number; } | represents the size of the div containing the chart area | | ScalarObject | <R, O> { [key: string]: ScaleFunction<R, O>; } | contains a scale function for each object key | | Axis | { x: Partial<AxisProps>; y: Partial<AxisProps>; } | represents the axis configuration object | | AxisProps | { format(d: any, i: number): string; tickLabelProps( d: any, i: number): { fontWeight: number; strokeWidth: number \| string; textAnchor: string; fontSize: number \| string; }; tickFormat(d: any, i?: number): string \| number; tickStroke: number \| string; labelProps: Object; tickFormat(d: string \| number, i?: number): string \| number; label: string; numTicks: number; stroke: string; } | represents the configuration for an x or y axis | | MouseMove | { event: React.SyntheticEvent; xPoints: number[] \| string[]; xScale: ScaleFunction<any, any>; yScale: ScaleFunction<any, any>; yScales: false \| { [key: string]: ScaleFunction<any, any> }; dataKeys: string[]; datum?: Object; } | represents the mouseMove event driving tooltip behavior | | InheritedChartProps|{ noTool: boolean; axes: Axis; xPoints: string[] | number[]; declareBar(): void; type: string; orientation?: 'horizontal'; mouseMove(args: any): void; mouseLeave(): void; xKey?: string; yKey?: string; height: number; width: number; margin: Margin; size: Size; yPoints: string[] | number[]; data: GenericData[]; xScale: ScaleFunction<any, any>; inheritedScale: ScaleFunction<any, any>; children: any; }| props cloned into children by theChartAreacomponent usingrecursiveCloneChildren| |State |{ width: number; height: number; xScale?: ScaleFunction<Range, Output>; yScale?: ScaleFunction<Range, Output>; yScales?: { [key: string]: ScaleFunction<any, any> } | false; biaxialChildren?: boolean; dataKeys?: string[]; yPoints: number[] | string[]; xPoints: number[] | string[]; } | contains the state of the processed data returned in Promise fromprepChartData` |