New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

west-pad

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

west-pad

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

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

west-pad

Behold, a far superior alternative to left-pad.

Inserts padding to the West of a string.

Install

npm install west-pad

Usage

  • 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;
  • 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"
  • 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

ParamTypeRequiredDescription
directionDirection or numberyes"N", "S", "E" or "W", or a number representing degrees from North

Class Method updateDirection

ParamTypeRequiredDescription
directionDirection or numberyes"N", "S", "E" or "W", or a number representing degrees from North

Class Method pad

ParamTypeRequiredDescription
sstringyesthe target string to pad
multiplicandnumberno; default = 1the number of times parameter p will be padded
pstringno; default = " "the string that will pad target string s multiplicand times

Class Method turnAroundThenPad

ParamTypeRequiredDescription
sstringyesthe target string to pad
multiplicandnumberno; default = 1the number of times parameter p will be padded
pstringno; default = " "the string that will pad target string s multiplicand times

Function westPad

ParamTypeRequiredDescription
directionDirection or numberyes"N", "S", "E" or "W", or a number representing degrees from North
sstringyesthe target string to pad
multiplicandnumberno; default = 1the number of times parameter p will be padded
pstringno; default = " "the string that will pad target string s multiplicand times

Function notWestPad

ParamTypeRequiredDescription
directionDirection or numberyes"N", "S", "E" or "W", or a number representing degrees from North
sstringyesthe target string to pad
multiplicandnumberno; default = 1the number of times parameter p will be padded
pstringno; default = " "the string that will pad target string s multiplicand times

FAQs

Package last updated on 30 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts