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 🙏

© 2024 – Pkg Stats / Ryan Hefner

curved-polygon

v1.0.1

Published

A utility to generate path string for curved polygons in SVG

Downloads

27

Readme

curved-polygon: A tiny library for creating regular polygons with rounded corners in SVG

curved-poly-demo

Installation

For legacy environments (UMD bundle), direct usage in the browser

<script src="https://unpkg.com/curved-polygon@latest"></script>

As an npm package

npm install curved-polygon

roundedPolygonByCircumRadius(options)

options properties

  • circumRadius (number, required) size of the polygon, contained inside a circle of this provided value
  • [borderRadius] (number, default = 0, optional) radius of the curved polygon corner
  • [sideCount] (number, default = 3, optional) number of polygon sides
  • [cx] (number, default = 0, optional) polygon center x position
  • [cy] (number, default = 0, optional) polygon center y position
  • [rotate] (number, default = 0, optional) rotation angle in degrees

Usage (circumradius):

import { roundedPolygonByCircumRadius } from 'curved-polygon'

const pathStringC = roundedPolygonByCircumRadius({
  circumRadius: 200,
  sideCount: 5,
  borderRadius: 10,
  cx: 150,
  cy: 150,
  rotate: 15,
})
// "M 260.291625178441 311.8033988749895 A 10 10 1.2566370614359172 0 0 269.8021903413926 304.89356881873897 L 337.96616337613284 95.10643118126106 A 10 10 1.2566370614359172 0 0 334.333450736106 83.92609129376211 L 155.87785252292477 -45.72949016875157 A 10 10 1.2566370614359172 0 0 144.1221474770753 -45.729490168751596 L -34.33345073610599 83.92609129376206 A 10 10 1.2566370614359172 0 0 -37.96616337613278 95.106431181261 L 30.197809658607397 304.8935688187389 A 10 10 1.2566370614359172 0 0 39.708374821558934 311.8033988749895 z"
// set this to the "d" attribute of a <path> SVG element

return value

The return value is an object with the following properties:

  • d (string) SVG path string to be used as a value to the d attributes of a <path> element
  • meta (object) contains helpful values: sideLength, circumRadius, inRadius, minSideLength, and borderRadius
  • warnings (an array of strings)
  • errors (an array of strings)

roundedPolygonBySideLength(options)

options properties

  • circumRadius (number, required) size of the polygon, contained inside a circle of this provided value
  • [borderRadius] (number, default = 0, optional) radius of the curved polygon corner
  • [sideCount] (number, default = 3, optional) number of polygon sides
  • [cx] (number, default = 0, optional) polygon center x position
  • [cy] (number, default = 0, optional) polygon center y position
  • [rotate] (number, default = 0, optional) rotation angle in degrees

Usage (side length):

import { roundedPolygonBySideLength } from 'curved-polygon'

const pathStringS = roundedPolygonBySideLength({
  sideLength: 200,
  sideCount: 5,
  borderRadius: 10,
  cx: 150,
  cy: 150,
  rotate: 90,
})
// "M 242.7345747199464 287.63819204711734 A 10 10 1.2566370614359172 0 0 252.24513988289794 280.7283619908668 L 309.55825899209157 104.33671884433718 A 10 10 1.2566370614359172 0 0 305.92554635206477 93.15637895683824 L 155.87785252292474 -15.85965183915954 A 10 10 1.2566370614359172 0 0 144.1221474770753 -15.859651839159568 L -5.9255463520647425 93.1563789568382 A 10 10 1.2566370614359172 0 0 -9.558258992091538 104.33671884433714 L 47.75486011710204 280.7283619908668 A 10 10 1.2566370614359172 0 0 57.26542528005358 287.63819204711734 z"
// set this to the "d" attribute of a <path> SVG element

return value

The return value is an object with the following properties:

  • d (string) SVG path string to be used as a value to the d attributes of a <path> element
  • meta (object) contains helpful values: sideLength, circumRadius, inRadius, minSideLength, and borderRadius
  • warnings (an array of strings)
  • errors (an array of strings)

Demos