https://github.com/dalikewara/vcmpad
String padding generator with custom Left/Right-Padding style
https://github.com/dalikewara/vcmpad
generator helper javascript lps lpz npm rps rpz string tool toolkit vascomm
Last synced: 30 days ago
JSON representation
String padding generator with custom Left/Right-Padding style
- Host: GitHub
- URL: https://github.com/dalikewara/vcmpad
- Owner: dalikewara
- License: mit
- Created: 2019-02-09T12:45:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-08-29T19:04:54.000Z (almost 4 years ago)
- Last Synced: 2025-08-21T01:22:30.702Z (10 months ago)
- Topics: generator, helper, javascript, lps, lpz, npm, rps, rpz, string, tool, toolkit, vascomm
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://nodei.co/npm/vcmpad/)
[](https://img.shields.io/npm/v/vcmpad.svg?style=flat)
[](https://img.shields.io/circleci/project/github/dalikewara/vcmpad.svg?style=flat)
[](https://img.shields.io/github/languages/top/dalikewara/vcmpad.svg?style=flat)
[](https://img.shields.io/npm/dt/vcmpad.svg?style=flat)
[](https://img.shields.io/librariesio/dependents/npm/vcmpad.svg?style=flat)
[](https://img.shields.io/github/issues/dalikewara/vcmpad.svg?style=flat)
[](https://img.shields.io/github/last-commit/dalikewara/vcmpad.svg?style=flat)
[](https://img.shields.io/npm/l/vcmpad.svg?style=flat)
# Fast, lightweight, and customable string padding generator
String padding generator with custom Left/Right-Padding style. It allows you to generate string padding format such as LPS *(Left Padding Space)*, LPZ *(Left Padding Zero)*, RPS *(Right Padding Space)*, and RPZ *(Right Padding Zero)*—or even you can create your own custom format.
### Installation
NPM
```console
npm install vcmpad --save
```
Browser
```js
// Bower
bower install vcmpad --save
```
### Initialization
NPM
```js
const vcmpad = require('vcmpad');
```
Browser
```js
// Bower
```
# Quickstart
There are two basic functions (`vcmpad.left` and `vcmpad.right`) to create String-Padding format using `vcmpad`, and they're absolutelly easy to use.
```js
vcmpad.left(n, val, format[optional], direction[optional]);
```
- Arguments
- *string|integer* **n**
- *string|integer* **val**
- *string|integer* **format** [optional]
- *default* space | ' '
- *boolean* **direction** [optional]
- *default* true
- only takes effect if `val.length > n`.
- if *false*, return last `n.length` characters.
### Left-Padding
A simple LPS format can be done like this:
```js
var str = vcmpad.left(10, 'test');
console.log(str); // output ' test'
```
Next, you may try to make other Left-Padding combinations, for example:
```js
vcmpad.left(10, 'test', '0'); // output '000000test'
vcmpad.left(10, 'test', 'left'); // output 'leftleftle'
vcmpad.left(10, 'test', 'left', false); // output 'ftlefttest'
vcmpad.left(10, 'test1234567890'); // output 'test123456'
```
### Right-Padding
A simple RPS format can be done like this:
```js
var str = vcmpad.right(10, 'test');
console.log(str); // output 'test '
```
Next, you may try to make other Right-Padding combinations, for example:
```js
vcmpad.right(10, 'test', '0'); // output 'test000000'
vcmpad.right(10, 'test', 'right'); // output 'testrightr'
vcmpad.right(10, 'test', 'right', false); // output 'rightright'
vcmpad.right(10, 'test1234567890'); // output 'test123456'
```
### Direction
The `direction` argument gives you option where string position should be returned if length of result or value higger than the number of `n` argument—basicly, it is first `n length` characters or last `n length` charatecrs.
```js
vcmpad.left(10, 'test1234567890'); // output 'test123456'
vcmpad.left(10, 'test1234567890', false); // output '1234567890'
vcmpad.left(10, 'test', 'left'); // output 'leftleftle'
vcmpad.left(10, 'test', 'left', false); // output 'ftlefttest'
```
# Release
### Changelog
See [https://github.com/dalikewara/vcmpad/blob/master/CHANGELOG.md](https://github.com/dalikewara/vcmpad/blob/master/CHANGELOG.md).
### Credits
Copyright © 2019 [Dali Kewara](https://www.dalikewara.com).
### License
[MIT License](https://github.com/dalikewara/vcmpad/blob/master/LICENSE)