array-limits
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var extendStatics=function(t,r){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var i in r)r.hasOwnProperty(i)&&(t[i]=r[i])})(t,r)};function __extends(t,r){function i(){this.constructor=t}extendStatics(t,r),t.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}var ArrayLimitException=function(e){function n(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var i=e.apply(this,t)||this;return i.name="ArrayLimitException",i.message="Array is set to have "+t[0]+" elements only. Array is now full.",Error.captureStackTrace(i,n),i}return __extends(n,e),n}(RangeError),InvalidLimitValueException=function(e){function n(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var i=e.apply(this,t)||this;return i.name="InvalidLimitValueException",i.message="Minimum array limit should be 1",Error.captureStackTrace(i,n),i}return __extends(n,e),n}(RangeError);Array.prototype.isFull=function(){return this.length>=this.limit},Array.prototype.full=function(){if(this.limit||(this.limit=1e6),this.isFull())throw new ArrayLimitException(this.limit);return this},Array.prototype.limit=function(t){if(t<1)throw new InvalidLimitValueException;return this.limit=t,this},Array.prototype.push=function(){var t=Array.prototype.push;return function(){return this.full(),t.apply(this,arguments)}}(),exports.ArrayLimitException=ArrayLimitException,exports.InvalidLimitValueException=InvalidLimitValueException; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var extendStatics=function(t,r){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var i in r)r.hasOwnProperty(i)&&(t[i]=r[i])})(t,r)};function __extends(t,r){function i(){this.constructor=t}extendStatics(t,r),t.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}var ArrayLimitException=function(e){function n(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var i=e.apply(this,t)||this;return i.name="ArrayLimitException",i.message="Array is set to have "+t[0]+" elements only. Array is now full.",Error.captureStackTrace(i,n),i}return __extends(n,e),n}(RangeError),InvalidLimitValueException=function(e){function n(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var i=e.apply(this,t)||this;return i.name="InvalidLimitValueException",i.message="Minimum array limit should be 1",Error.captureStackTrace(i,n),i}return __extends(n,e),n}(RangeError);Array.prototype.isFull=function(){return this.length>=this.limit},Array.prototype.availableSpace=function(){return this.limit-this.length},Array.prototype.full=function(){if(this.limit||(this.limit=1e6),this.isFull())throw new ArrayLimitException(this.limit);return this},Array.prototype.limit=function(t){if(t<1)throw new InvalidLimitValueException;return this.limit=t,this},Array.prototype.push=function(){var t=Array.prototype.push;return function(){return this.full(),t.apply(this,arguments)}}(),exports.ArrayLimitException=ArrayLimitException,exports.InvalidLimitValueException=InvalidLimitValueException; |
{ | ||
"name": "array-limits", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A way of telling that everything is possible", | ||
@@ -31,3 +31,3 @@ "main": "dist/index.js", | ||
], | ||
"author": "yakovmeister <so@tfwno.gf>", | ||
"author": "mocking@it <so@tfwno.gf>", | ||
"license": "MIT", | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
@@ -9,3 +9,3 @@ # array-limits | ||
### Adding limit | ||
### Setting limit | ||
@@ -15,7 +15,25 @@ ```javascript | ||
arr.limit(4); | ||
arr.limit(4); // if not set, defaults to 1000000 | ||
arr.push(0); // should throw an error since 4 is the limit of the array | ||
``` | ||
### Checking array's free space | ||
```javascript | ||
const arr = [0, 0, 0]; | ||
console.log(arr.availableSpace()); // should return the available space of an array | ||
``` | ||
### checking if array is full | ||
```javascript | ||
const arr = [0, 0, 0, 0]; | ||
console.log(arr.isFull()); // should return a boolean that tells if array is full or not | ||
``` | ||
## Note | ||
* This is not intended for something serious, the only reason of it's existence is to prove a point. Yes, everything is possible. | ||
<!-- Markdown link & img dfn's --> | ||
@@ -22,0 +40,0 @@ [npm-image]: https://img.shields.io/npm/v/array-limits.svg?style=flat-square |
Sorry, the diff of this file is not supported yet
7118
80
41