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

chars.js

v0.3.0

Published

A single-ascii-character utility

Downloads

31

Readme

chars.js

About single ascii characters.

install with npm: npm install --save chars.js

API

Chars.ASCII_RANGE_...

Chars.ASCII_RANGE_... are static const arrays with only two indices: [bottomOfRange, topOfRange]. These ranges are directly related to the ordinal values of the ascii-table.

The following ranges are defined in chars.js:

|Range |Ordinal range |Characters found in range |:-------------------------------|--------------|:----------------------------- |Chars.ASCII_RANGE_UPPERCASE |[65,90] |ABCDEFGHIJKLMNOPQRSTUVWXYZ |Chars.ASCII_RANGE_LOWERCASE |[97,122] |abcdefghijklmnopqrstuvwxyz |Chars.ASCII_RANGE_NUMBERS |[48,57] |0123456789 |Chars.ASCII_RANGE_SPECIAL_1 |[32,47] |(white space) !"#$%&'()*+,-./ |Chars.ASCII_RANGE_SPECIAL_2 |[58,64] |:;<=>?@ |Chars.ASCII_RANGE_SPECIAL_3 |[91,96] |[\]^_ |Chars.ASCII_RANGE_SPECIAL_4 |[123,126] |{\|}~ |Chars.ASCII_RANGE_ALL(printable)|[32,126] |(white space) !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{\|}~

Chars.REGEXP_SPECIAL_CHARS

<array> REGEXP_SPECIAL_CHARS

Returns an array (like a set) with all special characters used in regular expressions.

I use this for one of my other libraries, strings.js, for escaping a string to prepare for making a new RegExp.

Chars.ascii

<string> Chars.ascii( <string>/<number> ordinal )

Returns the ascii character found at ordinal.

var space= Chars.ascii( 32 );
// ' '

Chars.ordinal

<number> Chars.ordinal( <string>/<number> char )

Returns the ordinal for char.

var ordSpace= Chars.ordinal( ' ' );			
// 32

Chars.isUpper

<boolean> Chars.isUpper( <string>/<number> char )

Returns true if char is uppercase.

var test= Chars.isUpper( 'z' );				
// false

Chars.isLower

<boolean> Chars.isLower( <string>/<number> char )

Returns true if char is lowercase.

var test= Chars.isLower( 'z' );				
// true

Chars.isAlpha

<boolean> Chars.isAlpha( <string>/<number> char )

Returns true if char is uppercase or lowercase alpha.

var test= Chars.isAlpha( 'a' );				
// true

Chars.isNumeric

<boolean> Chars.isNumeric( <string>/<number> char )

Returns true if char is a number.

var test= Chars.isNumeric( '0' );			
// true
var test= Chars.isNumeric( 0 );				
// true

Chars.isSpecial

<boolean> Chars.isSpecial( <string>/<number> char )

Returns true if char is a special character from the SPECIAL_1,2,3 or 4 range.

var test= Chars.isSpecial( '.' );			
// true

Chars.isAlphaNumeric

<boolean> Chars.isAlphaNumeric( <string>/<number> char )

Returns true if char is a uppercase, lowercase or number.

var test= Chars.isAlphaNumeric( 'A' );		
// true
var test= Chars.isAlphaNumeric( 1 );		
// true

Chars.random

<string> Chars.random( range )

Returns a random character in range range. range defaults to the Chars.ASCII_RANGE_ALL range

var test= Chars.random( Chars.ASCII_RANGE_UPPERCASE );
// returns a single random character between 'A' and 'Z'

Chars.prototype.constructor

<this> constructor( <string>/<number> char, <array> range )

char can be a number character or ordinal, range has the format of ASCII_RANGE

var char= new Chars( '?' );
// I will be using this char instance for the following examples.

Chars.prototype.get

<string> get()

Returns this.char

console.log( char.get() );					
// '?'

Chars.prototype.set

<string> set( <string>/<number> char )

char can be a number character or ordinal. If char is an ordinal, the character represented by ordinal will be set.

console.log( char.set('!') );				
// '!'

Chars.prototype.next

<string> next( <string>/<number> amount )

Proceed this.char to the following ascii character and returns it, if no arguments are given. Proceed to amount ascii characters ahead, limited by this.range, if amount is set.

console.log( char.next() );					
//	'@'

Chars.prototype.prev

<this> prev( <string>/<number> amount )

Sets and returns this.char to the predecessor of the current ascii character in the ascii-table, if no arguments are given. If amount is given, it will decrease and set to the amount characters back in the ascii table.

prev is limited to the current active range. So, casting a prev on the bounds of the range will keep returning this bound.

console.log( char.prev() );					
//	'!'

The remaining methods are similar in working as the static versions by the same name, they only do not require a string argument, they use the objects string instead.

Chars.prototype.isUpper

<boolean> isUpper()

Chars.prototype.isLower

<boolean> isLower()

Chars.prototype.isAlpha

<boolean> isAlpha()

Chars.prototype.isNumeric

<boolean> isNumeric()

Chars.prototype.isSpecial

<boolean> isSpecial()

Chars.prototype.isAlphaNumeric

<boolean> isAlphaNumeric()

Chars.prototype.random

<string> random()


change log

0.2.0

  • changed license to MIT
  • updated readme

0.1.5

  • chars.js now depends on types.js.
  • Some fixes and cleanup.
  • Added some basic Jasmine tests, still incomplete, will finish later
  • Updated the readme.

###license MIT