Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chars.js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chars.js - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

chars.js

@@ -195,3 +195,3 @@ // Generated by CoffeeScript 1.8.0

}
return this;
return this.char;
};

@@ -198,0 +198,0 @@

@@ -1,1 +0,1 @@

(function(){var r,n,t,i,e,o,u,c,f;o=function(r){return e(r)||i(r)};e=function(r){return typeof r==="string"};i=function(r){return typeof r==="number"&&r===r};c=function(r){return!(typeof r==="object")&&r instanceof Array};t=function(r){return typeof r==="number"&&r!==r};f=function(r){return!t(r)};u=function(r){var n,i,e,o,u;if(c(r)){return 0}for(n=o=0,u=r.length;o<u;n=++o){e=r[n];if(t(i=parseInt(r[n],10))){return n}r[n]=i}return r.length};n=function(){function r(){}r.inRange=function(r,n){if(t(r=parseInt(r,10))||u(n)<2){return false}return r>=n[0]&&r<=n[1]};r.force=function(r,n){if(f(r=parseInt(r,10))){return r}if(f(n=parseInt(n,10))){return n}return 0};r.limit=function(r,n){if(u(n)<2){return 0}if(t(r=parseInt(r,10))||r<n[0]){return n[0]}if(r>n[1]){return n[1]}return r};r.random=function(r,n){if(u([r,n])<2){return 0}if(n<r){return r}n=n-r+1;return Math.floor(Math.random()*n+r)};return r}();r=function(){r.ASCII_RANGE_UPPERCASE=[65,90];r.ASCII_RANGE_LOWERCASE=[97,122];r.ASCII_RANGE_NUMBERS=[48,57];r.ASCII_RANGE_SPECIAL_1=[32,47];r.ASCII_RANGE_SPECIAL_2=[58,64];r.ASCII_RANGE_SPECIAL_3=[91,96];r.ASCII_RANGE_SPECIAL_4=[123,126];r.ASCII_RANGE_ALL=[32,126];r.REGEXP_SPECIAL_CHARS=["?","\\","[","]","(",")","*","+",".","/","|","^","$","<",">","-","&"];r.force=function(r,n){if(o(r)){return(r+"")[0]}if(o(n)){return(n+"")[0]}return""};r.ascii=function(r){return String.fromCharCode(n.force(r))};r.ordinal=function(t){return n.force(r.force(t).charCodeAt())};r.isUpper=function(t){return n.inRange(r.ordinal(t),r.ASCII_RANGE_UPPERCASE)};r.isLower=function(t){return n.inRange(r.ordinal(t),r.ASCII_RANGE_LOWERCASE)};r.isAlpha=function(n){return r.isUpper(n)||r.isLower(n)};r.isNumeric=function(t){return n.inRange(r.ordinal(t),r.ASCII_RANGE_NUMBERS)};r.isSpecial=function(n){return!(r.isAlphaNumeric(n)||n===" ")};r.isAlphaNumeric=function(n){return r.isAlpha(n)||r.isNumeric(n)};r.random=function(t){var i,e;if(t==null){t=r.ASCII_RANGE_ALL}if(c(t)||t.length<2){return""}e=n.limit(t[0],t);i=n.limit(t[1],t);return r.ascii(n.random(e,i))};function r(n,t){if(t==null||c(t)){this.range=r.ASCII_RANGE_ALL}else{this.range=t}this.set(n);Object.defineProperty(this,"ordinal",{get:function(){return r.ordinal(this.char)}});Object.defineProperty(this,"ascii",{get:function(){return this.char}})}r.prototype.get=function(){return this.char};r.prototype.set=function(t){if(i(t)&&t>9){this.char=r.ascii(n.limit(t,this.range))}else{this.char=r.force(t,r.ascii(this.range[0]))}return this};r.prototype.next=function(r){return this.set(this.ordinal+n.force(r,1))};r.prototype.prev=function(r){return this.set(this.ordinal-n.force(r,1))};r.prototype.isUpper=function(){return r.isUpper(this.char)};r.prototype.isLower=function(){return r.isLower(this.char)};r.prototype.isAlpha=function(){return r.isAlpha(this.char)};r.prototype.isNumeric=function(){return r.isNumeric(this.char)};r.prototype.isSpecial=function(){return r.isSpecial(this.char)};r.prototype.isAlphaNumeric=function(){return r.isAlphaNumeric(this.char)};r.prototype.random=function(){return this.set(r.random())};return r}();if(typeof window!=="undefined"&&window!==null){window.Chars=r}else{module.exports=r}}).call(this);
(function(){var n,r,t,i,e,o,u,c,s;o=function(n){return e(n)||i(n)},e=function(n){return"string"==typeof n},i=function(n){return"number"==typeof n&&n===n},c=function(n){return!("object"==typeof n)&&n instanceof Array},t=function(n){return"number"==typeof n&&n!==n},s=function(n){return!t(n)},u=function(n){var r,i,e,o,u;if(c(n))return 0;for(r=o=0,u=n.length;u>o;r=++o){if(e=n[r],t(i=parseInt(n[r],10)))return r;n[r]=i}return n.length},r=function(){function n(){}return n.inRange=function(n,r){return t(n=parseInt(n,10))||u(r)<2?!1:n>=r[0]&&n<=r[1]},n.force=function(n,r){return s(n=parseInt(n,10))?n:s(r=parseInt(r,10))?r:0},n.limit=function(n,r){return u(r)<2?0:t(n=parseInt(n,10))||n<r[0]?r[0]:n>r[1]?r[1]:n},n.random=function(n,r){return u([n,r])<2?0:n>r?n:(r=r-n+1,Math.floor(Math.random()*r+n))},n}(),n=function(){function n(r,t){this.range=null==t||c(t)?n.ASCII_RANGE_ALL:t,this.set(r),Object.defineProperty(this,"ordinal",{get:function(){return n.ordinal(this.char)}}),Object.defineProperty(this,"ascii",{get:function(){return this.char}})}return n.ASCII_RANGE_UPPERCASE=[65,90],n.ASCII_RANGE_LOWERCASE=[97,122],n.ASCII_RANGE_NUMBERS=[48,57],n.ASCII_RANGE_SPECIAL_1=[32,47],n.ASCII_RANGE_SPECIAL_2=[58,64],n.ASCII_RANGE_SPECIAL_3=[91,96],n.ASCII_RANGE_SPECIAL_4=[123,126],n.ASCII_RANGE_ALL=[32,126],n.REGEXP_SPECIAL_CHARS=["?","\\","[","]","(",")","*","+",".","/","|","^","$","<",">","-","&"],n.force=function(n,r){return o(n)?(n+"")[0]:o(r)?(r+"")[0]:""},n.ascii=function(n){return String.fromCharCode(r.force(n))},n.ordinal=function(t){return r.force(n.force(t).charCodeAt())},n.isUpper=function(t){return r.inRange(n.ordinal(t),n.ASCII_RANGE_UPPERCASE)},n.isLower=function(t){return r.inRange(n.ordinal(t),n.ASCII_RANGE_LOWERCASE)},n.isAlpha=function(r){return n.isUpper(r)||n.isLower(r)},n.isNumeric=function(t){return r.inRange(n.ordinal(t),n.ASCII_RANGE_NUMBERS)},n.isSpecial=function(r){return!(n.isAlphaNumeric(r)||" "===r)},n.isAlphaNumeric=function(r){return n.isAlpha(r)||n.isNumeric(r)},n.random=function(t){var i,e;return null==t&&(t=n.ASCII_RANGE_ALL),c(t)||t.length<2?"":(e=r.limit(t[0],t),i=r.limit(t[1],t),n.ascii(r.random(e,i)))},n.prototype.get=function(){return this.char},n.prototype.set=function(t){return this.char=i(t)&&t>9?n.ascii(r.limit(t,this.range)):n.force(t,n.ascii(this.range[0])),this.char},n.prototype.next=function(n){return this.set(this.ordinal+r.force(n,1))},n.prototype.prev=function(n){return this.set(this.ordinal-r.force(n,1))},n.prototype.isUpper=function(){return n.isUpper(this.char)},n.prototype.isLower=function(){return n.isLower(this.char)},n.prototype.isAlpha=function(){return n.isAlpha(this.char)},n.prototype.isNumeric=function(){return n.isNumeric(this.char)},n.prototype.isSpecial=function(){return n.isSpecial(this.char)},n.prototype.isAlphaNumeric=function(){return n.isAlphaNumeric(this.char)},n.prototype.random=function(){return this.set(n.random())},n}(),"undefined"!=typeof window&&null!==window?window.Chars=n:module.exports=n}).call(this);
{
"name": "chars.js",
"version": "0.1.2",
"version": "0.1.3",
"description": "A tiny Javascript single-ascii-character utility/library",

@@ -5,0 +5,0 @@ "main": "chars.min.js",

chars.js
========
<br/>
All about single ascii characters. Experimental and under development, will evolve over time.
No proper readme yet, incomplete, will try to update soon.
I use Chars mainly as a document for static character related data and methods. Parts of it can be found in my
other libraries, like strings.js for example.
<br/><br/><br/><br/>
<br/>
___
You can use `npm install chars.js` if you're on node.js.

@@ -16,12 +20,13 @@ ___

> ASCII_RANGE is an array with two indices: [bottomOfRange, topOfRange]
> ASCII_RANGE is an array with two indices: [bottomOfRange, topOfRange]. These ranges are directly related
> to the ordinal values from the ascii-table.
**Chars.ASCII_RANGE_UPPERCASE**
**Chars.ASCII_RANGE_LOWERCASE**
**Chars.ASCII_RANGE_NUMBERS**
**Chars.ASCII_RANGE_SPECIAL_1**
**Chars.ASCII_RANGE_SPECIAL_2**
**Chars.ASCII_RANGE_SPECIAL_3**
**Chars.ASCII_RANGE_SPECIAL_4**
**Chars.ASCII_RANGE_ALL**
**Chars.ASCII_RANGE_UPPERCASE**<br/>
**Chars.ASCII_RANGE_LOWERCASE**<br/>
**Chars.ASCII_RANGE_NUMBERS**<br/>
**Chars.ASCII_RANGE_SPECIAL_1**<br/>
**Chars.ASCII_RANGE_SPECIAL_2**<br/>
**Chars.ASCII_RANGE_SPECIAL_3**<br/>
**Chars.ASCII_RANGE_SPECIAL_4**<br/>
**Chars.ASCII_RANGE_ALL**<br/>

@@ -33,5 +38,22 @@ **Chars.REGEXP_SPECIAL_CHARS**

> 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.
```javascript
var space= Chars.ascii( 32 ); // ' '
```
**Chars.ordinal**
> `<number> Chars.ordinal( <string>/<number> char )`
> Returns the ordinal for char.
```javascript
var ordSpace= Chars.ordinal( ' ' ); // 32
```
**Chars.isUpper**

@@ -42,2 +64,6 @@ > `<boolean> Chars.isUpper( <string>/<number> char )`

```javascript
var test= Chars.isUpper( 'z' ); // false
```
**Chars.isLower**

@@ -48,2 +74,6 @@ > `<boolean> Chars.isLower( <string>/<number> char )`

```javascript
var test= Chars.isLower( 'z' ); // true
```
**Chars.isAlpha**

@@ -54,2 +84,6 @@ > `<boolean> Chars.isAlpha( <string>/<number> char )`

```javascript
var test= Chars.isAlpha( 'a' ); // true
```
**Chars.isNumeric**

@@ -60,2 +94,7 @@ > `<boolean> Chars.isNumeric( <string>/<number> char )`

```javascript
var test= Chars.isNumeric( '0' ); // true
var test= Chars.isNumeric( 0 ); // true
```
**Chars.isSpecial**

@@ -66,2 +105,7 @@ > `<boolean> Chars.isSpecial( <string>/<number> char )`

```javascript
var test= Chars.isSpecial( '.' ); // true
```
**Chars.isAlphaNumeric**

@@ -72,2 +116,7 @@ > `<boolean> Chars.isAlphaNumeric( <string>/<number> char )`

```javascript
var test= Chars.isAlphaNumeric( 'A' ); // true
var test= Chars.isAlphaNumeric( 1 ); // true
```
**Chars.random**

@@ -78,7 +127,17 @@ > `<string> Chars.random( range )`

```javascript
var test= Chars.random( Chars.ASCII_RANGE_UPPERCASE );
// returns a single random character between 'A' and 'Z'
```
**Chars.prototype.constructor**
> `<object> constructor( <string>/<number> char, <array> range )`
> `<this> constructor( <string>/<number> char, <array> range )`
> char can be a number character or ordinal, range has the format of ASCII_RANGE
```javascript
var char= new Chars( '?' );
// I will be using this char instance for the following examples.
```
**Chars.prototype.get**

@@ -89,32 +148,58 @@ > `<string> get()`

```javascript
console.log( char.get() ); // '?'
```
**Chars.prototype.set**
> `<this> set( <string>/<number> char )`
> `<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.
```javascript
console.log( char.set('!') ); // '!'
```
**Chars.prototype.next**
> `<this> next( <string>/<number> amount )`
> `<string> next( <string>/<number> amount )`
> Proceed this.char to the following ascii character, if no arguments are given. Proceed to amount ascii characters
> 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.
```javascript
console.log( char.next() ); // '@'
```
**Chars.prototype.prev**
> `<this> prev( <string>/<number> amount )`
> Proceed this.char to the following ascii character, if no arguments are given. Proceed to amount ascii characters
> back, limited by this.range, if amount is set.
> 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.
```javascript
console.log( char.prev() ); // '!'
```
**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()`

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc