Skip to content

Commit

Permalink
feat: add kv-analytics library
Browse files Browse the repository at this point in the history
  • Loading branch information
emuvente committed Nov 30, 2023
1 parent e2aa676 commit d5a032f
Show file tree
Hide file tree
Showing 10 changed files with 12,350 additions and 8,020 deletions.
21 changes: 21 additions & 0 deletions @kiva/kv-analytics/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
parser: 'vue-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
},
plugins: [
'@typescript-eslint',
],
extends: [
'../../.eslintrc.cjs',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
],
rules: {
// allow imports without file extensions
'import/extensions': 'off',
// allow `any` type
'@typescript-eslint/no-explicit-any': ['off'],
},
};
4 changes: 4 additions & 0 deletions @kiva/kv-analytics/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
};
43 changes: 43 additions & 0 deletions @kiva/kv-analytics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "kv-analytics",
"version": "1.0.0",
"type": "module",
"publishConfig": {
"access": "public"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "tsup src/*.ts --format cjs,esm --dts --clean",
"lint": "eslint --ext .ts,.vue ./src",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kiva/kv-ui-elements.git"
},
"bugs": {
"url": "https://github.com/kiva/kv-ui-elements/issues"
},
"homepage": "https://github.com/kiva/kv-ui-elements#readme",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^29.1.1",
"tsup": "^6.7.0",
"typescript": "^5.3.2"
}
}
63 changes: 63 additions & 0 deletions @kiva/kv-analytics/src/SimpleQueue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Utility class to help with creating and managing a basic queue
* - This implementation uses array properites and is meant for small queues of items
*/
export default class SimpleQueue<T> {
items: T[];

itemLimit: number;

/**
* Initialize a queue to hold items in an array
*/
constructor(options?: { itemLimit?: number }) {
this.items = [];
this.itemLimit = options?.itemLimit ?? 200;
}

/**
* Add an item to the queue
*/
add(item: T) {
// limit items added to queue
if (this.items.length === this.itemLimit) {
return false;
}
this.items.push(item);
}

/**
* Remove an item from the queue
*/
remove() {
return this.items.shift();
}

/**
* Check for items in the queue
*/
isEmpty() {
return this.items.length === 0;
}

/**
* Get the item at the front of the queue
*/
peek() {
return !this.isEmpty() ? this.items[0] : undefined;
}

/**
* Remove all items from the queue
*/
reset() {
this.items.length = 0;
}

/**
* Get the length of the queue
*/
get length() {
return this.items.length;
}
}
Loading

0 comments on commit d5a032f

Please sign in to comment.