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.4 to 0.2.0

LICENSE

186

chars.js
// Generated by CoffeeScript 1.8.0
(function() {
var Chars, Numbers, isNaN, isNumber, isString, isStringOrNumber, mapStringToNumber, notArray, notNaN;
"use strict";
var Chars, mapStringToNumber, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
isStringOrNumber = function(value) {
return isString(value) || isNumber(value);
};
if (typeof window !== "undefined" && window !== null) {
_ = window.Types;
} else if (typeof module !== "undefined" && module !== null) {
_ = require('types.js');
}
isString = function(value) {
return typeof value === 'string';
};
isNumber = function(value) {
return (typeof value === 'number') && (value === value);
};
notArray = function(value) {
return !(typeof value === 'object') && (value instanceof Array);
};
isNaN = function(value) {
return (typeof value === 'number') && (value !== value);
};
notNaN = function(value) {
return !isNaN(value);
};
mapStringToNumber = function(array) {
var index, nr, value, _i, _len;
if (notArray(array)) {
if (_.notArray(array)) {
return 0;

@@ -36,3 +21,3 @@ }

value = array[index];
if (isNaN(nr = parseInt(array[index], 10))) {
if (_.isNaN(nr = parseInt(array[index], 10))) {
return index;

@@ -45,51 +30,36 @@ }

Numbers = (function() {
function Numbers() {}
_.inRange = function(nr, range) {
if ((_.isNaN(nr = parseInt(nr, 10))) || (mapStringToNumber(range) < 2)) {
return false;
}
return (nr >= range[0]) && (nr <= range[1]);
};
Numbers.inRange = function(nr, range) {
if ((isNaN(nr = parseInt(nr, 10))) || (mapStringToNumber(range) < 2)) {
return false;
}
return (nr >= range[0]) && (nr <= range[1]);
};
_.limit = function(nr, range) {
if (mapStringToNumber(range) < 2) {
return 0;
}
if ((_.isNaN(nr = parseInt(nr, 10))) || (nr < range[0])) {
return range[0];
}
if (nr > range[1]) {
return range[1];
}
return nr;
};
Numbers.force = function(nr, replacement) {
if (notNaN(nr = parseInt(nr, 10))) {
return nr;
}
if (notNaN(replacement = parseInt(replacement, 10))) {
return replacement;
}
_.random = function(min, max) {
if (mapStringToNumber([min, max]) < 2) {
return 0;
};
}
if (max < min) {
return min;
}
max = (max - min) + 1;
return Math.floor((Math.random() * max) + min);
};
Numbers.limit = function(nr, range) {
if (mapStringToNumber(range) < 2) {
return 0;
}
if ((isNaN(nr = parseInt(nr, 10))) || (nr < range[0])) {
return range[0];
}
if (nr > range[1]) {
return range[1];
}
return nr;
};
Chars = (function(_super) {
__extends(Chars, _super);
Numbers.random = function(min, max) {
if (mapStringToNumber([min, max]) < 2) {
return 0;
}
if (max < min) {
return min;
}
max = (max - min) + 1;
return Math.floor((Math.random() * max) + min);
};
return Numbers;
})();
Chars = (function() {
Chars.ASCII_RANGE_UPPERCASE = [65, 90];

@@ -113,26 +83,16 @@

Chars.force = function(char, replacement) {
if (isStringOrNumber(char)) {
return (char + '')[0];
}
if (isStringOrNumber(replacement)) {
return (replacement + '')[0];
}
return '';
};
Chars.ascii = function(ordinal) {
return String.fromCharCode(Numbers.force(ordinal));
return String.fromCharCode(_.forceNumber(ordinal, 0));
};
Chars.ordinal = function(char) {
return Numbers.force(Chars.force(char).charCodeAt());
return _.forceNumber(_.forceString(char != null ? char[0] : void 0).charCodeAt(), 0);
};
Chars.isUpper = function(char) {
return Numbers.inRange(Chars.ordinal(char), Chars.ASCII_RANGE_UPPERCASE);
return _.inRange(Chars.ordinal(char), Chars.ASCII_RANGE_UPPERCASE);
};
Chars.isLower = function(char) {
return Numbers.inRange(Chars.ordinal(char), Chars.ASCII_RANGE_LOWERCASE);
return _.inRange(Chars.ordinal(char), Chars.ASCII_RANGE_LOWERCASE);
};

@@ -145,9 +105,5 @@

Chars.isNumeric = function(char) {
return Numbers.inRange(Chars.ordinal(char), Chars.ASCII_RANGE_NUMBERS);
return _.inRange(Chars.ordinal(char), Chars.ASCII_RANGE_NUMBERS);
};
Chars.isSpecial = function(char) {
return !(Chars.isAlphaNumeric(char) || (char === ' '));
};
Chars.isAlphaNumeric = function(char) {

@@ -157,2 +113,6 @@ return Chars.isAlpha(char) || Chars.isNumeric(char);

Chars.isSpecial = function(char) {
return ('' !== (char = _.forceString(char))) && !Chars.isAlphaNumeric(char);
};
Chars.random = function(range) {

@@ -163,12 +123,12 @@ var max, min;

}
if (notArray(range) || range.length < 2) {
if (_.notArray(range) || range.length < 2) {
return '';
}
min = Numbers.limit(range[0], range);
max = Numbers.limit(range[1], range);
return Chars.ascii(Numbers.random(min, max));
min = _.limit(range[0], range);
max = _.limit(range[1], range);
return Chars.ascii(_.random(min, max));
};
function Chars(char, range) {
if ((range == null) || notArray(range)) {
if ((range == null) || _.notArray(range)) {
this.range = Chars.ASCII_RANGE_ALL;

@@ -179,12 +139,2 @@ } else {

this.set(char);
Object.defineProperty(this, 'ordinal', {
get: function() {
return Chars.ordinal(this.char);
}
});
Object.defineProperty(this, 'ascii', {
get: function() {
return this.char;
}
});
}

@@ -197,6 +147,6 @@

Chars.prototype.set = function(char) {
if (isNumber(char) && char > 9) {
this.char = Chars.ascii(Numbers.limit(char, this.range));
if (_.isNumber(char) && char > 9) {
this.char = Chars.ascii(_.limit(char, this.range));
} else {
this.char = Chars.force(char, Chars.ascii(this.range[0]));
this.char = _.forceString(char != null ? char[0] : void 0, Chars.ascii(this.range[0]));
}

@@ -207,7 +157,7 @@ return this.char;

Chars.prototype.next = function(amount) {
return this.set(this.ordinal + Numbers.force(amount, 1));
return this.set(this.ordinal + _.forceNumber(amount, 1));
};
Chars.prototype.prev = function(amount) {
return this.set(this.ordinal - Numbers.force(amount, 1));
return this.set(this.ordinal - _.forceNumber(amount, 1));
};

@@ -245,7 +195,21 @@

})();
})(_);
Object.defineProperty(Chars.prototype, 'ordinal', {
get: function() {
return Chars.ordinal(this.char);
}
});
Object.defineProperty(Chars.prototype, 'ascii', {
get: function() {
return this.char;
}
});
Chars._ = _;
if (typeof window !== "undefined" && window !== null) {
window.Chars = Chars;
} else {
} else if (typeof module !== "undefined" && module !== null) {
module.exports = Chars;

@@ -252,0 +216,0 @@ }

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

(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);
(function(){"use strict";var r,t,n,i={}.hasOwnProperty,e=function(r,t){function n(){this.constructor=r}for(var e in t)i.call(t,e)&&(r[e]=t[e]);return n.prototype=t.prototype,r.prototype=new n,r.__super__=t.prototype,r};"undefined"!=typeof window&&null!==window?n=window.Types:"undefined"!=typeof module&&null!==module&&(n=require("types.js")),t=function(r){var t,i,e,o,u;if(n.notArray(r))return 0;for(t=o=0,u=r.length;u>o;t=++o){if(e=r[t],n.isNaN(i=parseInt(r[t],10)))return t;r[t]=i}return r.length},n.inRange=function(r,i){return n.isNaN(r=parseInt(r,10))||t(i)<2?!1:r>=i[0]&&r<=i[1]},n.limit=function(r,i){return t(i)<2?0:n.isNaN(r=parseInt(r,10))||r<i[0]?i[0]:r>i[1]?i[1]:r},n.random=function(r,n){return t([r,n])<2?0:r>n?r:(n=n-r+1,Math.floor(Math.random()*n+r))},r=function(r){function t(r,i){this.range=null==i||n.notArray(i)?t.ASCII_RANGE_ALL:i,this.set(r)}return e(t,r),t.ASCII_RANGE_UPPERCASE=[65,90],t.ASCII_RANGE_LOWERCASE=[97,122],t.ASCII_RANGE_NUMBERS=[48,57],t.ASCII_RANGE_SPECIAL_1=[32,47],t.ASCII_RANGE_SPECIAL_2=[58,64],t.ASCII_RANGE_SPECIAL_3=[91,96],t.ASCII_RANGE_SPECIAL_4=[123,126],t.ASCII_RANGE_ALL=[32,126],t.REGEXP_SPECIAL_CHARS=["?","\\","[","]","(",")","*","+",".","/","|","^","$","<",">","-","&"],t.ascii=function(r){return String.fromCharCode(n.forceNumber(r,0))},t.ordinal=function(r){return n.forceNumber(n.forceString(null!=r?r[0]:void 0).charCodeAt(),0)},t.isUpper=function(r){return n.inRange(t.ordinal(r),t.ASCII_RANGE_UPPERCASE)},t.isLower=function(r){return n.inRange(t.ordinal(r),t.ASCII_RANGE_LOWERCASE)},t.isAlpha=function(r){return t.isUpper(r)||t.isLower(r)},t.isNumeric=function(r){return n.inRange(t.ordinal(r),t.ASCII_RANGE_NUMBERS)},t.isAlphaNumeric=function(r){return t.isAlpha(r)||t.isNumeric(r)},t.isSpecial=function(r){return""!==(r=n.forceString(r))&&!t.isAlphaNumeric(r)},t.random=function(r){var i,e;return null==r&&(r=t.ASCII_RANGE_ALL),n.notArray(r)||r.length<2?"":(e=n.limit(r[0],r),i=n.limit(r[1],r),t.ascii(n.random(e,i)))},t.prototype.get=function(){return this.char},t.prototype.set=function(r){return this.char=n.isNumber(r)&&r>9?t.ascii(n.limit(r,this.range)):n.forceString(null!=r?r[0]:void 0,t.ascii(this.range[0])),this.char},t.prototype.next=function(r){return this.set(this.ordinal+n.forceNumber(r,1))},t.prototype.prev=function(r){return this.set(this.ordinal-n.forceNumber(r,1))},t.prototype.isUpper=function(){return t.isUpper(this.char)},t.prototype.isLower=function(){return t.isLower(this.char)},t.prototype.isAlpha=function(){return t.isAlpha(this.char)},t.prototype.isNumeric=function(){return t.isNumeric(this.char)},t.prototype.isSpecial=function(){return t.isSpecial(this.char)},t.prototype.isAlphaNumeric=function(){return t.isAlphaNumeric(this.char)},t.prototype.random=function(){return this.set(t.random())},t}(n),Object.defineProperty(r.prototype,"ordinal",{get:function(){return r.ordinal(this.char)}}),Object.defineProperty(r.prototype,"ascii",{get:function(){return this.char}}),r._=n,"undefined"!=typeof window&&null!==window?window.Chars=r:"undefined"!=typeof module&&null!==module&&(module.exports=r)}).call(this);
{
"name": "chars.js",
"version": "0.1.4",
"description": "A tiny Javascript single-ascii-character utility/library",
"version": "0.2.0",
"description": "A single-ascii-character utility",
"main": "chars.min.js",

@@ -19,8 +19,6 @@ "scripts": {

"ascii",
"ordinal",
"tools",
"library"
"ordinal"
],
"author": "Dennis Raymondo <phazelift@gmail.com> (https://github.com/phazelift/)",
"license": "GPL-3",
"license": "MIT",
"bugs": {

@@ -30,4 +28,3 @@ "url": "https://github.com/phazelift/chars.js/issues"

"homepage": "https://github.com/phazelift/chars.js",
"dependencies": {},
"devDependencies": {}
"dependencies": { "types.js": "1.3.9" }
}
chars.js
========
About single ascii characters.
<br/>
All about single ascii characters. Experimental and under development, will evolve over time.
>install with npm: `npm install --save chars.js`
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/>
___
You can use `npm install chars.js` if you're on node.js.
___
API
---
> 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_...**
**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/>
> 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] |` !"#$%&'()*+,-./`
|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] |` !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`\``abcdefghijklmnopqrstuvwxyz{|}~`
**Chars.REGEXP_SPECIAL_CHARS**
> `<array> REGEXP_SPECIAL_CHARS`

@@ -45,3 +49,4 @@

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

@@ -55,3 +60,4 @@

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

@@ -65,3 +71,4 @@

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

@@ -75,3 +82,4 @@

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

@@ -85,3 +93,4 @@

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

@@ -95,4 +104,6 @@

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

@@ -107,3 +118,4 @@

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

@@ -117,4 +129,6 @@

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

@@ -148,3 +162,4 @@

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

@@ -158,3 +173,4 @@

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

@@ -169,3 +185,4 @@

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

@@ -183,3 +200,4 @@

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

@@ -211,1 +229,24 @@

---
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

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