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

pattern-printing

v1.0.0

Published

A collection of pattern printing functions — concentric squares, diamonds, circles, zigzags, fractals, letter shapes and more. Ported from C logic.

Readme

pattern-printing

A collection of ASCII pattern printing functions for Node.js — ported from original C logic.
Every function accepts n as input and returns the pattern as a plain string.

Install

npm install pattern-printing

Quick Start

const patterns = require('pattern-printing');

// Print a concentric square of size 4
console.log(patterns.concentricSquare(4));
// 4444444
// 4333334
// 4322234
// 4321234
// 4322234
// 4333334
// 4444444

// Print a hollow circle of radius 4
console.log(patterns.hollowCircle(4));
//   *****
//  **   **
// **     **
// *       *
// ...

// Print a zigzag of height 5
console.log(patterns.zigzag(5));

CLI Usage

# List all available patterns
node index.js

# Run a specific pattern with n
node index.js concentricSquare 4
node index.js zigzag 6
node index.js sierpinskiCross 3
node index.js hollowDiamond 5

API Reference

concentricSquare(n)

Prints a (2n−1) × (2n−1) grid where each cell shows n minus its minimum distance to any edge. Produces nested square rings of numbers.

concentricSquare(4)
→ 4444444
  4333334
  4322234
  4321234
  4322234
  4333334
  4444444

hollowConcentricSquare(n)

Like concentricSquare but only draws the outer border and the two main diagonals. All other cells are spaces.

hollowConcentricSquare(4)
→ 4444444
  43   34
  4 2 2 4
  4  1  4
  4 2 2 4
  43   34
  4444444

checkerboard(n)

n × n checkerboard where * appears when (i+j) is even.

checkerboard(4)
→ * * 
   * *
  * * 
   * *

checkerNumbered(n)

n × n board where the value at (i,j) is n minus the min-distance to any edge, adjusted ±1 by parity of (i+j).

checkerNumbered(4)
→ 4343
  3323
  4222
  3323

hollowCircle(radius)

Hollow circle drawn using Euclidean distance. A * is placed wherever the distance from the centre is within ±0.5 of radius.

hollowCircle(4)
→   *****  
   **   ** 
  **     **
  *       *
  *       *
  *       *
  **     **
   **   ** 
    *****  

invertedTriangle(n)

Row i has i leading spaces then 2*(n−1−i)+1 stars.

invertedTriangle(5)
→ *********
   *******
    *****
     ***
      *

recursiveFrames(n)

Nested hollow square frames on an n × n grid. Frames step inward by 2 each time so there is always a gap between them.

recursiveFrames(9)
→ * * * * * * * * *
  *               *
  *   * * * * *   *
  *   *       *   *
  *   *   *   *   *
  ...

hollowDiamond(n)

Diamond shape made of two halves. Each row has two runs of * with a hollow gap in between that widens towards the centre.

hollowDiamond(5)
→ ***** *****
  ****   ****
  ***     ***
  **       **
  *         *
  *         *
  ...

concentricDiamond(n)

Concentric diamond rings using the formula |mid−i| + |mid−j| == mid for the outer ring, with inner rings shifted inward.

concentricDiamond(5)
→      *     
     ***    
    *****   
   *******  
  **** **** 
  ****   ****
  ...

zigzag(n)

n-row zigzag of * characters. Stars alternate between a shrinking gap 2*(n−1−i)−1 and an expanding gap 2*i−1 as rows progress.

zigzag(4)
→ *               *               *
   *             * *             *
    *           *   *           *
     *         *     *         *

letterJ(n)

n × n grid rendering the letter J — full top bar, right stem going down, then a curved base going left and up.

letterJ(8)
→ ********
        *
        *
  ...
  *      *
   *     *

letterU(n)

n × n grid rendering the letter U — two vertical bars at top, then converging diagonals meeting at a point at the bottom. n must be even.

letterU(10)
→ *        *
  *        *
  ...
    *    *
      **

sierpinskiCross(k)

Sierpinski-cross fractal on a 3^k × 3^k grid. Each 3×3 block fills the four cardinal neighbours and leaves the corners and centre empty. Recurse until size == 1.

| k | Grid size | |---|-----------| | 1 | 3 × 3 | | 2 | 9 × 9 | | 3 | 27 × 27 | | 4 | 81 × 81 |

sierpinskiCross(2)
→     *    
     ***   
      *    
  *  *  * 
  *********
   *  *  * 
      *    
     ***   
      *    

matrixZeroSpread(matrix)

Given a 2-D array of 0s and 1s, spreads each 1 across its entire row and column. Returns the resulting matrix as a string.

matrixZeroSpread([[1,0,0,1],[0,0,1,0],[0,0,0,0]])
→ 1111
  1111
  1010

modDiagonal(n)

6 rows × 101 columns. A * appears at column j in row i when (i + j) % n === 0. Row 0 is blank.

modDiagonal(20)
→ (blank)
                   *                   *  ...
                  *                   *   ...

modifiedPascal(n)

Pascal's triangle where the last element of every row is decremented by 1.

modifiedPascal(5)
→ 1
  1 0
  1 1 0
  1 2 1 0
  1 3 3 1 0

License

MIT