Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
laffed committed Aug 30, 2023
0 parents commit ff624b8
Show file tree
Hide file tree
Showing 13 changed files with 4,825 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These owners will be the default owners for everything in the repo.
# review when someone opens a pull request.
* [email protected]
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish
on:
push:
branches:
- "main"

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3
with:
node-version: 16.x
cache: "pnpm"

- run: pnpm install --frozen-lockfile
- name: Create Release MR
id: changesets
uses: changesets/action@v1
with:
publish: pnpm run build

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/dist
/coverage
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Laffed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
142 changes: 142 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
## west-pad

Behold, a far superior alternative to (`left-pad`)[https://github.com/left-pad/left-pad].

Insert padding to the West of a string.

## Install

```bash
npm install west-pad
```

## Usage

0. First grab the cardinal direction from your device. This direction can be the cardinal char value or a number value representing degrees from North.

```ts
type Direction = "N" | "S" | "E" | "W" | number;
```

1a. west-pad exports a class to hold cardinal state for your repeated padding convenience

```ts
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"
```

1b. alternatively you can use the standalone function

```ts
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!

```ts
import WestPad from 'west-pad';

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

const westPad = new WestPad(direction);

const paddedWestFromMethod = westPad.pad(s, 3);
console.log(paddedWestFromMethod); // " Hello World"

const paddedEastFromMethod = westPad.turnAroundThenPad(s, 3);
console.log(paddedEastFromMethod); // "Hello World "
```

```ts
import {westPad, notWestPad} from 'west-pad';

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

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

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

## 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


## Troubleshooting

***Padding is being added in the wrong direction?**

Step 1. Try turning your computer/device in a different direction.
Step 2. Profit
30 changes: 30 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Config } from 'jest';

const config: Config = {
preset: "ts-jest",
extensionsToTreatAsEsm: ['.ts'],
testEnvironment: "node",
verbose: true,
moduleDirectories: ['node_modules', 'src'],
transform: {
'^.+\\.ts$': [
'ts-jest',
{
useESM: true
}
]
},
collectCoverageFrom: [
'src/**/*.{ts}'
],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
}
};

export default config;
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "west-pad",
"version": "0.1.0",
"description": "a better left-pad: adds padding in the West cardinal direction",
"author": "laffed",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts",
"lint": "tsc",
"test": "jest --coverage"
},
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@types/jest": "^29.5.4",
"jest": "^29.6.4",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
"dependencies": {
"cardinal-direction": "^1.1.1"
}
}
Loading

0 comments on commit ff624b8

Please sign in to comment.