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

west-pad

v2.0.1

Published

a better left-pad: adds padding in the West cardinal direction

Downloads

11

Readme

west-pad

Behold, a far superior alternative to left-pad.

Inserts padding to the West of a string.

Install

npm install west-pad

Usage

  1. First grab the cardinal direction from your device. This direction can be the cardinal char value or a number value representing degrees from North.
type Direction = "N" | "S" | "E" | "W" | number;
  1. west-pad exports a class to hold cardinal state for your repeated padding convenience
import WestPad from 'west-pad';

const direction = getDeviceDirection(); // "N" or 0
const westPad = new WestPad(direction);

const s = "Hello World";

console.log(westPad(s)); // " Hello World"

console.log(westPad(s, 5)); // "     Hello World"

console.log(westPad(s, 5, "+")); // "+++++Hello World"

const newDirection = "E";
westPad.updateDirection(newDirection);

console.log(westPad(s, 2)); // "Hello World\n \n"
  1. alternatively you can use the standalone function
import { westPad } from 'west-pad';

const direction = getDeviceDirection(); // "N"
const s = "Hello World";

console.log(westPad(direction, s, 3)); // "   Hello World"
console.log(westPad("S", s, 3, "+")); // "Hello World+++"
console.log(westPad(220, s, 3)); // " \n \n \nHello World"

What if I want to East pad?

Don't worry, west-pad has you covered. There is both a class method and a standalone function for you East-ers!

import WestPad from 'west-pad';

const direction = "N";
const s = "Hello World";

const westPad = new WestPad(direction);

const paddedEastFromMethod = westPad.turnAroundThenPad(s, 3);
console.log(paddedEastFromMethod); // "Hello World   "
import { notWestPad } from 'west-pad';

const direction = "N";
const s = "Hello World";

const paddedEast = notWestPad(direction, s, 3);
console.log(paddedEast); // "Hello World   "

Troubleshooting

Padding is being added in the wrong direction?

Step 1. Try turning your computer/device in a different direction.
Step 2. Profit

Parameters

Class constructor

| Param | Type | Required | Description | | ------ | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | direction | Direction or number | yes | "N", "S", "E" or "W", or a number representing degrees from North

Class Method updateDirection

| Param | Type | Required | Description | | ------ | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | direction | Direction or number | yes | "N", "S", "E" or "W", or a number representing degrees from North

Class Method pad

| Param | Type | Required | Description | | ------ | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | s | string | yes | the target string to pad | multiplicand | number | no; default = 1 | the number of times parameter p will be padded | p | string | no; default = " " | the string that will pad target string s multiplicand times

Class Method turnAroundThenPad

| Param | Type | Required | Description | | ------ | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | s | string | yes | the target string to pad | multiplicand | number | no; default = 1 | the number of times parameter p will be padded | p | string | no; default = " " | the string that will pad target string s multiplicand times

Function westPad

| Param | Type | Required | Description | | ------ | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | direction | Direction or number | yes | "N", "S", "E" or "W", or a number representing degrees from North | s | string | yes | the target string to pad | multiplicand | number | no; default = 1 | the number of times parameter p will be padded | p | string | no; default = " " | the string that will pad target string s multiplicand times

Function notWestPad

| Param | Type | Required | Description | | ------ | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | direction | Direction or number | yes | "N", "S", "E" or "W", or a number representing degrees from North | s | string | yes | the target string to pad | multiplicand | number | no; default = 1 | the number of times parameter p will be padded | p | string | no; default = " " | the string that will pad target string s multiplicand times