leftpad

package module
v0.0.0-...-fc15ef7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2016 License: BSD-2-Clause Imports: 3 Imported by: 0

README

left-pad

Go package to left pad a string with a character.

Inspired by the "left-pad" NPM package (and the fiasco that happened after its removal).

Install
go get github.com/keltia/leftpad 
Usage
import 'github.com/keltia/leftpad'

leftpad.LeftPad("foo", 5)       # => "  foo"
leftpad.LeftPad("foobar", 8)    # => "  foobar"
leftpad.LeftPad("foobar", 6)    # => "foobar"

leftpad.LeftPadStr("foo", 5, "X") # => "XXfoo"

Documentation

Overview

 This package implements the leftpad function, inspired by the NPM (JS)
 package of the same name.

 Two functions are defined:

     import "leftpad"

	 // pad with spacex
     str, err := LeftPad(s, n)

     // pad with specified character
     str, err := func LeftPadStr(s, n, c)

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidChar = errors.New("Invalid character")

Functions

func LeftPad

func LeftPad(s string, n int) (string, error)

func LeftPadStr

func LeftPadStr(s string, n int, c string) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL