ring-buffer-ts
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,(function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(i,s,function(t){return e[t]}.bind(null,s));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);class i{constructor(e){if(this.buffer=[],this.pos=0,e<0)throw new RangeError("The size does not allow negative values.");this.size=e}static fromArray(e,t=0){const r=new i(t);return r.fromArray(e,0===t),r}getSize(){return this.size}getPos(){return this.pos}getBufferLength(){return this.buffer.length}add(...e){e.forEach(e=>{this.buffer[this.pos]=e,this.pos=(this.pos+1)%this.size})}get(e){if(e<0&&(e+=this.buffer.length),!(e<0||e>this.buffer.length))return this.buffer.length<this.size?this.buffer[e]:this.buffer[(this.pos+e)%this.size]}getFirst(){return this.get(0)}getLast(){return this.get(-1)}remove(e,t=1){if(e<0&&(e+=this.buffer.length),e<0||e>this.buffer.length)return[];const r=this.toArray(),i=r.splice(e,t);return this.fromArray(r),i}removeFirst(){return this.remove(0)[0]}removeLast(){return this.remove(-1)[0]}toArray(){return this.buffer.slice(this.pos).concat(this.buffer.slice(0,this.pos))}fromArray(e,t=!1){if(!Array.isArray(e))throw new TypeError("Input value is not an array.");t&&this.resize(e.length),0!==this.size&&(this.buffer=e.slice(-this.size),this.pos=this.buffer.length%this.size)}clear(){this.buffer=[],this.pos=0}resize(e){if(e<0)throw new RangeError("The size does not allow negative values.");if(0===e)this.clear();else if(e!==this.size){const t=this.toArray();this.fromArray(t.slice(-e)),this.pos=this.buffer.length%e}this.size=e}isFull(){return this.buffer.length===this.size}isEmpty(){return 0===this.buffer.length}}r.d(t,"RingBuffer",(function(){return i}))}])})); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var s in r)("object"==typeof exports?exports:e)[s]=r[s]}}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{RingBuffer:()=>r});class r{static fromArray(e,t=0){const s=new r(t);return s.fromArray(e,0===t),s}constructor(e){if(this.buffer=[],this.pos=0,e<0)throw new RangeError("Invalid size.");this.size=e}getSize(){return this.size}getPos(){return this.pos}getBufferLength(){return this.buffer.length}add(...e){e.forEach((e=>{this.buffer[this.pos]=e,this.pos=(this.pos+1)%this.size}))}get(e){if(e<0&&(e+=this.buffer.length),!(e<0||e>this.buffer.length))return this.buffer.length<this.size?this.buffer[e]:this.buffer[(this.pos+e)%this.size]}getFirst(){return this.get(0)}getLast(){return this.get(-1)}remove(e,t=1){if(e<0&&(e+=this.buffer.length),e<0||e>this.buffer.length)return[];const r=this.toArray(),s=r.splice(e,t);return this.fromArray(r),s}removeFirst(){return this.remove(0)[0]}removeLast(){return this.remove(-1)[0]}toArray(){return this.buffer.slice(this.pos).concat(this.buffer.slice(0,this.pos))}fromArray(e,t=!1){if(!Array.isArray(e))throw new TypeError("Input value is not an array.");t&&this.resize(e.length),0!==this.size&&(this.buffer=e.slice(-this.size),this.pos=this.buffer.length%this.size)}clear(){this.buffer=[],this.pos=0}resize(e){if(e<0)throw new RangeError("The size does not allow negative values.");if(0===e)this.clear();else if(e!==this.size){const t=this.toArray();this.fromArray(t.slice(-e)),this.pos=this.buffer.length%e}this.size=e}isFull(){return this.buffer.length===this.size}isEmpty(){return 0===this.buffer.length}}return t})())); |
@@ -1,6 +0,1 @@ | ||
/** | ||
* RingBuffer | ||
* | ||
* (c) Copyright 2019 Dominik-Andreas Geng (domske@github) | ||
*/ | ||
export declare class RingBuffer<T> { | ||
@@ -13,5 +8,5 @@ /** | ||
static fromArray<T>(data: T[], size?: number): RingBuffer<T>; | ||
private buffer; | ||
private size; | ||
private pos; | ||
protected buffer: T[]; | ||
protected size: number; | ||
protected pos: number; | ||
/** | ||
@@ -18,0 +13,0 @@ * Creates a new ring buffer. |
{ | ||
"name": "ring-buffer-ts", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "A circular array buffer written in modern TypeScript.", | ||
"scripts": { | ||
"build": "webpack", | ||
"lint": "tslint -p tsconfig.json", | ||
"lint": "eslint ./src --ext .ts", | ||
"test": "jest", | ||
@@ -12,2 +12,3 @@ "coverage": "jest --coverage", | ||
"docs": "typedoc src", | ||
"build-test": "tsc test/import.ts", | ||
"prepare": "npm run build", | ||
@@ -32,3 +33,6 @@ "prepublishOnly": "npm test && npm run lint", | ||
], | ||
"author": "Dominik-Andreas Geng", | ||
"author": { | ||
"name": "Dominik-Andreas Geng", | ||
"url": "https://github.com/domske/" | ||
}, | ||
"license": "MIT", | ||
@@ -40,16 +44,16 @@ "repository": { | ||
"devDependencies": { | ||
"@types/jest": "^24.0.23", | ||
"clean-webpack-plugin": "^3.0.0", | ||
"jest": "^24.9.0", | ||
"prettier": "^1.19.1", | ||
"ts-jest": "^24.1.0", | ||
"ts-loader": "^6.2.1", | ||
"tslint": "^5.20.1", | ||
"tslint-config-prettier": "^1.18.0", | ||
"tslint-consistent-codestyle": "^1.16.0", | ||
"typedoc": "^0.15.2", | ||
"typescript": "^3.7.2", | ||
"webpack": "^4.41.2", | ||
"webpack-cli": "^3.3.10" | ||
"@types/jest": "^29.2.4", | ||
"@typescript-eslint/eslint-plugin": "^5.46.1", | ||
"@typescript-eslint/parser": "^5.46.1", | ||
"clean-webpack-plugin": "^4.0.0", | ||
"eslint": "^8.29.0", | ||
"jest": "^29.3.1", | ||
"prettier": "^2.8.1", | ||
"ts-jest": "^29.0.3", | ||
"ts-loader": "^9.4.2", | ||
"typedoc": "^0.23.22", | ||
"typescript": "^4.9.4", | ||
"webpack": "^5.75.0", | ||
"webpack-cli": "^5.0.1" | ||
} | ||
} |
# Ring Buffer | ||
[![Version][version]][package] [![MIT License][license-badge]][license] | ||
![](readme/logo.png) | ||
@@ -17,3 +19,3 @@ | ||
Missing feature? Note that you can export and import the buffer as array and you can do what ever you want with the array. You can also consider to create an issue here and pull-request to add features. | ||
Missing feature? Note that you can export and import the buffer as an array and do whatever you want with the array. For example using slice. You can also consider creating an issue here and adding features via pull request. Note that the compatibility of protected members in the next minor or patch releases cannot be guaranteed and is not documented. | ||
@@ -26,4 +28,2 @@ ## Install | ||
[NPM Package](https://www.npmjs.com/package/ring-buffer-ts) | ||
## Usage | ||
@@ -44,1 +44,6 @@ | ||
[Documentation](https://domske.github.io/ring-buffer-ts/) | ||
[license-badge]: https://img.shields.io/npm/l/ring-buffer-ts.svg?style=flat-square | ||
[license]: https://opensource.org/licenses/MIT | ||
[version]: https://img.shields.io/npm/v/ring-buffer-ts.svg?style=flat-square | ||
[package]: https://www.npmjs.com/package/ring-buffer-ts |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20361
7
47
91