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

leading-chars

v0.0.4

Published

Creates leading characters for a string or number

Downloads

1,503

Readme

leading-chars

Build Status Dependency Status devDependency Status

##Description

Creates leading or trailing characters in a string or number

##Install

Install with NPM

npm install leading-chars

##Require

var LeadingChars = require('leading-chars')

##LeadingChars(options)

LeadingChars is a constructor function that takes options and exports the user function.

##options

If you don't understand these notes, check out the examples, they should make it more clear.

  • options is an object with the following properties:
    • len is a number for how many characters to fill or concatenate (depending on overall).
    • overall is a boolean. It specifies whether the character is filled up to len, (true), or if the character is concatenated len times, (false).
    • character is the character that is added to the string or number.
    • leading is a boolean of whether character should be added to the beginning or the end. If you want the concatenated characters to lead the string or number, set this to true. If you want them characters to trail, set this to false.
  • Returns: constructed(input, options)

##constructed(input, options) ###input This is the string or number that is appended to. This is not mutated.

###options Same as LeadingChars()s options.

##Examples

Leading Zeroes:

var leadingZeroes = LeadingChars({
	len: 8,
	overall: true,
	character: '0',
	leading: true
})

leadingZeroes('5f39a6') //returns '005f39a6'
leadingZeroes('')       //returns '00000000'
leadingZeroes('ftw')    //returns '00000ftw'

Indent with one tab:

var indent = LeadingChars({
	len: 1,
	overall: false,
	character: '\t',
	leading: true
})

indent('Hey what is up')  //returns '\tHey what is up'
indent()                  //returns '\t'
indent('blah', {len: 2})  //returns '\t\tblah'

Append full stops: (Sometimes referred to as 'periods')

var addFullStop = LeadingChars({
	len: 1,
	overall: false,
	character: '.',
	leading: false
})

addFullStop('Hey what is up') //returns 'Hey what is up.'
addFullStop(null)             //returns '.'
addFullStop('blah', {len: 3}) //returns 'blah...'

Fill with J's:

var fillWithJs = LeadingChars({
	len: 4,
	overall: true,
	character: 'J',
	leading: true
})

fillWithJs('a')     //returns 'JJJa'
fillWithJs('aaa')   //returns 'Jaaa'
fillWithJs('aaaaa') //returns 'aaaaa'

Prefix 2 E's:

var prefixTwoEs = LeadingChars({
	len: 2,
	overall: false,
	character: 'E',
	leading: true
})

prefixTwoEs('a')     //returns 'EEa'  
prefixTwoEs('aaa')   //returns 'EEaaa'  
prefixTwoEs('aaaaa') //returns 'EEaaaaa'

Leading Smileys:

var leadingSmileys = LeadingChars({
	len: 2,
	overall: false,
	character: ':) ',
	leading: true
})

leadingSmileys('lol')  //returns ':) :) lol'  
leadingSmileys('wat')  //returns ':) :) wat'  
leadingSmileys('uber') //returns ':) :) uber'

Trailing Frowneys:

var trailingFrowneys = LeadingChars({
	len: 1,
	overall: false,
	character: ' :(',
	leading: true
})

trailingFrowneys('no')     //returns 'no :('  
trailingFrowneys('so sad') //returns 'so sad :('  
trailingFrowneys('um why') //returns 'um why :('

##License

MIT