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

dsacjs

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dsacjs - npm Package Compare versions

Comparing version 0.0.2-test to 0.0.2

dist/algorithms/math/factorial.js

242

dist/dataStructures/DoublyLinkedList.js

@@ -11,11 +11,251 @@ "use strict";

this.next = null;
this.prev = null;
}
}
class DoublyLinkedList {
addAtIndex(index, value) {
if (index < 0 || index > this.size) {
throw new Error("Index out of bounds");
}
if (index === 0) {
this.addFirst(value);
return;
}
if (index === this.size) {
this.addLast(value);
return;
}
let current = this.head;
let i = 0;
while (current && i < index) {
current = current.next;
i++;
}
if (current) {
const newNode = new ListNode(value);
newNode.next = current;
newNode.prev = current.prev;
if (current.prev) {
current.prev.next = newNode;
}
current.prev = newNode;
this.size++;
}
}
constructor() {
this.logger = new Logger_1.default();
this.size = 0;
this.head = null;
this.logger.log("DoublyLinkedList created" + this.head);
this.tail = null;
}
add(indexOrValue, value) {
if (typeof indexOrValue === "number" && value) {
this.addAtIndex(indexOrValue, value);
}
else {
this.addLast(indexOrValue);
}
}
addFirst(value) {
const newNode = new ListNode(value);
if (this.isEmpty()) {
this.tail = newNode;
}
else {
newNode.next = this.head;
if (this.head) {
this.head.prev = newNode;
}
}
this.head = newNode;
this.size++;
}
addLast(value) {
const newNode = new ListNode(value);
if (this.isEmpty()) {
this.head = newNode;
}
else {
if (this.tail) {
this.tail.next = newNode;
}
newNode.prev = this.tail;
}
this.tail = newNode;
this.size++;
}
clear() {
this.head = null;
this.tail = null;
this.size = 0;
}
contains(value) {
let current = this.head;
while (current) {
if (current.value === value) {
return true;
}
current = current.next;
}
return false;
}
get(index) {
var _a;
if (index < 0 || index >= this.size) {
return null;
}
let current = this.head;
let i = 0;
while (current && i < index) {
current = current.next;
i++;
}
return (_a = current === null || current === void 0 ? void 0 : current.value) !== null && _a !== void 0 ? _a : null;
}
getFirst() {
var _a, _b;
return (_b = (_a = this.head) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
}
getLast() {
var _a, _b;
return (_b = (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
}
indexOf(value) {
let current = this.head;
let index = 0;
while (current) {
if (current.value === value) {
return index;
}
current = current.next;
index++;
}
return -1;
}
iterator() {
let current = this.head;
return {
next() {
if (current) {
const value = current.value;
current = current.next;
return { done: false, value };
}
return { done: true, value: null };
},
[Symbol.iterator]() {
return this;
},
};
}
isEmpty() {
return this.size === 0;
}
peek() {
var _a, _b;
return (_b = (_a = this.head) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
}
poll() {
return this.removeFirst();
}
print() {
if (this.isEmpty()) {
return this.logger.info("List is empty");
}
const listValues = [];
let current = this.head;
while (current) {
listValues.push(current.value);
current = current.next;
}
this.logger.info(listValues);
}
printReverse() {
if (this.isEmpty()) {
return this.logger.info("List is empty");
}
const listValues = [];
let current = this.tail;
while (current) {
listValues.push(current.value);
current = current.prev;
}
this.logger.info(listValues);
}
removeAt(index) {
if (index < 0 || index >= this.size) {
return null;
}
if (index === 0) {
return this.removeFirst();
}
if (index === this.size - 1) {
return this.removeLast();
}
let current = this.head;
let i = 0;
while (current && i < index) {
current = current.next;
i++;
}
if (current) {
if (current.prev) {
current.prev.next = current.next;
}
if (current.next) {
current.next.prev = current.prev;
}
this.size--;
return current.value;
}
return null;
}
removeFirst() {
var _a, _b;
if (this.isEmpty()) {
return null;
}
const value = (_b = (_a = this.head) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
if (this.size === 1) {
this.head = null;
this.tail = null;
}
else if (this.head) {
this.head = this.head.next;
if (this.head) {
this.head.prev = null;
}
}
this.size--;
return value;
}
removeLast() {
var _a, _b;
if (this.isEmpty()) {
return null;
}
const value = (_b = (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
if (this.size === 1) {
this.head = null;
this.tail = null;
}
else if (this.tail) {
this.tail = this.tail.prev;
if (this.tail) {
this.tail.next = null;
}
}
this.size--;
return value;
}
toArray() {
const listValues = [];
let current = this.head;
while (current) {
listValues.push(current.value);
current = current.next;
}
return listValues;
}
}
exports.default = DoublyLinkedList;

16

dist/dataStructures/Queue.js

@@ -11,4 +11,4 @@ "use strict";

}
enqueue(value) {
return this.list.addLast(value);
clear() {
this.list.clear();
}

@@ -18,4 +18,4 @@ dequeue() {

}
peek() {
return this.list.peek();
enqueue(value) {
return this.list.addLast(value);
}

@@ -25,4 +25,4 @@ isEmpty() {

}
size() {
return this.list.size;
peek() {
return this.list.peek();
}

@@ -32,6 +32,6 @@ print() {

}
clear() {
this.list.clear();
size() {
return this.list.size;
}
}
exports.default = Queue;

@@ -14,2 +14,29 @@ "use strict";

class SingleLinkedList {
addAtIndex(index, value) {
if (index < 0 || index > this.size) {
throw new Error("Index out of bounds");
}
if (index === 0) {
this.addFirst(value);
return;
}
if (index === this.size) {
this.addLast(value);
return;
}
let current = this.head;
let previous = null;
let i = 0;
while (i < index) {
previous = current;
current = (current === null || current === void 0 ? void 0 : current.next) || null;
i++;
}
const newNode = new ListNode(value);
newNode.next = current;
if (previous) {
previous.next = newNode;
}
this.size++;
}
constructor() {

@@ -21,13 +48,13 @@ this.logger = new Logger_1.default();

}
isEmpty() {
return this.size === 0;
add(indexOrValue, value) {
if (typeof indexOrValue === "number" && value !== undefined) {
this.addAtIndex(indexOrValue, value);
}
else {
this.addLast(indexOrValue);
}
}
peek() {
var _a, _b;
return (_b = (_a = this.head) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
}
addFirst(value) {
const newNode = new ListNode(value);
if (this.isEmpty()) {
this.head = newNode;
this.tail = newNode;

@@ -37,4 +64,4 @@ }

newNode.next = this.head;
this.head = newNode;
}
this.head = newNode;
this.size++;

@@ -46,12 +73,112 @@ }

this.head = newNode;
this.tail = newNode;
}
else {
if (this.tail) {
this.tail.next = newNode;
}
this.tail = newNode;
else if (this.tail) {
this.tail.next = newNode;
}
this.tail = newNode;
this.size++;
}
clear() {
this.head = null;
this.tail = null;
this.size = 0;
}
getFirst() {
var _a, _b;
return (_b = (_a = this.head) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
}
getLast() {
var _a, _b;
return (_b = (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
}
indexOf(value) {
let current = this.head;
let index = 0;
while (current) {
if (current.value === value) {
return index;
}
current = current.next;
index++;
}
return -1;
}
isEmpty() {
return this.size === 0;
}
peek() {
var _a, _b;
return (_b = (_a = this.head) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
}
poll() {
return this.removeFirst();
}
print() {
if (this.isEmpty()) {
return this.logger.info("List is empty");
}
let current = this.head;
const listValues = [];
while (current) {
listValues.push(current.value);
current = current.next;
}
this.logger.info(listValues);
}
printReverse() {
if (this.isEmpty()) {
return this.logger.info("List is empty");
}
let current = this.head;
const listValues = [];
while (current) {
listValues.unshift(current.value);
current = current.next;
}
this.logger.info(listValues);
}
remove(value) {
let current = this.head;
let previous = null;
while (current) {
if (current.value === value) {
if (previous) {
previous.next = current.next;
}
else {
this.head = current.next;
}
this.size--;
return true;
}
previous = current;
current = current.next;
}
return false;
}
removeAt(index) {
var _a;
if (index < 0 || index >= this.size) {
return null;
}
if (index === 0) {
return this.removeFirst();
}
if (index === this.size - 1) {
return this.removeLast();
}
let current = this.head;
let previous = null;
let i = 0;
while (i < index) {
previous = current;
current = (current === null || current === void 0 ? void 0 : current.next) || null;
i++;
}
if (previous) {
previous.next = (current === null || current === void 0 ? void 0 : current.next) || null;
}
this.size--;
return (_a = current === null || current === void 0 ? void 0 : current.value) !== null && _a !== void 0 ? _a : null;
}
removeFirst() {

@@ -95,6 +222,3 @@ var _a, _b, _c;

}
print() {
if (this.isEmpty()) {
return this.logger.info("List is empty");
}
toArray() {
let current = this.head;

@@ -106,22 +230,5 @@ const listValues = [];

}
this.logger.info(listValues);
return listValues;
}
printReverse() {
if (this.isEmpty()) {
return this.logger.info("List is empty");
}
let current = this.head;
const listValues = [];
while (current) {
listValues.unshift(current.value);
current = current.next;
}
this.logger.info(listValues);
}
clear() {
this.head = null;
this.tail = null;
this.size = 0;
}
}
exports.default = SingleLinkedList;

@@ -11,7 +11,7 @@ "use strict";

}
push(value) {
return this.list.addFirst(value);
clear() {
this.list.clear();
}
pop() {
return this.list.removeFirst();
isEmpty() {
return this.list.isEmpty();
}

@@ -21,15 +21,15 @@ peek() {

}
isEmpty() {
return this.list.isEmpty();
pop() {
return this.list.removeFirst();
}
size() {
return this.list.size;
}
print() {
return this.list.printReverse();
}
clear() {
this.list.clear();
push(value) {
return this.list.addFirst(value);
}
size() {
return this.list.size;
}
}
exports.default = Stack;

@@ -6,5 +6,21 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.binarySearch = exports.Logger = exports.LinkedList = exports.Queue = exports.Stack = exports.SingleLinkedList = void 0;
const binarySearch_1 = __importDefault(require("./Algorithms/binarySearch"));
exports.quickSort = exports.mergeSort = exports.insertionSort = exports.bubbleSort = exports.recursiveBinarySearch = exports.linearSearch = exports.factorial = exports.binarySearch = exports.Logger = exports.Deque = exports.LinkedList = exports.Queue = exports.Stack = exports.SingleLinkedList = void 0;
const factorial_1 = __importDefault(require("./algorithms/math/factorial"));
exports.factorial = factorial_1.default;
const binarySearch_1 = __importDefault(require("./algorithms/search/binarySearch"));
exports.binarySearch = binarySearch_1.default;
const linearSearch_1 = __importDefault(require("./algorithms/search/linearSearch"));
exports.linearSearch = linearSearch_1.default;
const recursiveBinarySearch_1 = __importDefault(require("./algorithms/search/recursiveBinarySearch"));
exports.recursiveBinarySearch = recursiveBinarySearch_1.default;
const bubbleSort_1 = __importDefault(require("./algorithms/sort/bubbleSort"));
exports.bubbleSort = bubbleSort_1.default;
const insertionSort_1 = __importDefault(require("./algorithms/sort/insertionSort"));
exports.insertionSort = insertionSort_1.default;
const mergeSort_1 = __importDefault(require("./algorithms/sort/mergeSort"));
exports.mergeSort = mergeSort_1.default;
const quickSort_1 = __importDefault(require("./algorithms/sort/quickSort"));
exports.quickSort = quickSort_1.default;
const Deque_1 = __importDefault(require("./dataStructures/Deque"));
exports.Deque = Deque_1.default;
const DoublyLinkedList_1 = __importDefault(require("./dataStructures/DoublyLinkedList"));

@@ -11,0 +27,0 @@ exports.LinkedList = DoublyLinkedList_1.default;

@@ -5,2 +5,10 @@ "use strict";

constructor(prefix) {
this.colors = {
log: "\x1b[32m",
error: "\x1b[31m",
warn: "\x1b[33m",
info: "\x1b[34m",
debug: "\x1b[35m",
reset: "\x1b[0m",
};
this.prefix = prefix;

@@ -10,6 +18,6 @@ }

if (this.prefix) {
console.log(`[${this.prefix}] ${data}`);
console.log(`[LOG] [${this.prefix}] ${data}`);
}
else {
console.log(data);
console.log(`[LOG] ${data}`);
}

@@ -19,6 +27,6 @@ }

if (this.prefix) {
console.error(`[${this.prefix}] ${data}`);
console.error(`[ERROR] [${this.prefix}] ${data}`);
}
else {
console.error(data);
console.error(`[ERROR] ${data}`);
}

@@ -28,6 +36,6 @@ }

if (this.prefix) {
console.warn(`[${this.prefix}] ${data}`);
console.warn(`[WARN] [${this.prefix}] ${data}`);
}
else {
console.warn(data);
console.warn(`[WARN] ${data}`);
}

@@ -37,6 +45,6 @@ }

if (this.prefix) {
console.info(`[${this.prefix}] ${data}`);
console.info(`[INFO] [${this.prefix}] ${data}`);
}
else {
console.info(data);
console.info(`[INFO] ${data}`);
}

@@ -46,6 +54,6 @@ }

if (this.prefix) {
console.debug(`[${this.prefix}] ${data}`);
console.debug(`[DEBUG] [${this.prefix}] ${data}`);
}
else {
console.debug(data);
console.debug(`[DEBUG] ${data}`);
}

@@ -55,6 +63,6 @@ }

if (this.prefix) {
console.trace(`[${this.prefix}] ${data}`);
console.trace(`[TRACE] [${this.prefix}] ${data}`);
}
else {
console.trace(data);
console.trace(`[TRACE] ${data}`);
}

@@ -64,6 +72,6 @@ }

if (this.prefix) {
console.group(`[${this.prefix}] ${data}`);
console.group(`[GROUP] [${this.prefix}] ${data}`);
}
else {
console.group(data);
console.group(`[GROUP] ${data}`);
}

@@ -70,0 +78,0 @@ }

{
"name": "dsacjs",
"version": "0.0.2-test",
"version": "0.0.2",
"description": "A high-performance JavaScript and TypeScript library offering a comprehensive set of efficient data structures. Simplify your algorithm implementation and data manipulation with optimized, easy-to-use tools.",

@@ -11,2 +11,5 @@ "main": "./dist/index.js",

],
"workspaces": [
"docs"
],
"scripts": {

@@ -50,3 +53,3 @@ "test": "jest --verbose",

},
"homepage": "https://github.com/gabriel-logan/dsacjs#readme",
"homepage": "https://gabriel-logan.github.io/DsacJs",
"devDependencies": {

@@ -53,0 +56,0 @@ "@babel/core": "^7.26.0",

# IN DEVELOPMENT
# DsacJs - Data Structures - Algorithm - Toolkit Collection
# DsacJs
## Data Structures - Algorithm - Toolkit Collection
A high-performance JavaScript and TypeScript library offering a comprehensive set of efficient data structures. Simplify your algorithm implementation and data manipulation with optimized, easy-to-use tools.
[![npm](https://img.shields.io/npm/v/dsacjs)](https://www.npmjs.com/package/dsacjs)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![npm downloads](https://img.shields.io/npm/dm/dsacjs.svg?style=flat-square)](https://npm-stat.com/charts.html?package=dsacjs)
## Documentation
- [Website Documentation](https://gabriel-logan.github.io/DsacJs/)
- [NPM Package](https://www.npmjs.com/package/dsacjs)
## CDN
```html
<script type="module">
import { LinkedList } from "https://cdn.jsdelivr.net/npm/dsacjs@0.0.1/+esm";
const linkedList = new LinkedList();
linkedList.add(1);
linkedList.add(2);
linkedList.add(3);
console.log(linkedList.toArray());
</script>
```
## Installation
```bash
npm install dsacjs
```
```bash
yarn add dsacjs
```
```bash
pnpm add dsacjs
```
```bash
bun add dsacjs
```
## Usage
```javascript
import { LinkedList } from "dsacjs";
const list = new LinkedList();
list.add(1);
list.add(2);
list.add(3);
console.log(list.toArray()); // [1, 2, 3]
```
## Features
- **Data Structures**: A comprehensive set of data structures including linked lists, stacks, queues, trees, graphs, and more.
- **Algorithms**: A collection of algorithms for sorting, searching, and other common tasks.
- **Toolkit**: A set of utility functions for working with data structures and algorithms.
## Why DsacJs?
- **Performance**: High-performance implementations with optimized algorithms and data structures.
- **Ease of Use**: Simplify your algorithm implementation and data manipulation with easy-to-use tools.
- **Comprehensive**: A comprehensive set of data structures, algorithms, and utility functions for all your needs.
## Contributing
Contributions are welcome! For feature requests and bug reports, please submit an issue. For code contributions, please follow the [contribution guidelines](CONTRIBUTING.md).
## License
DsacJs is [MIT licensed](LICENSE).
## Contributing
Thank you for considering contributing to DsacJs! We welcome all contributions, including bug reports, feature requests, and code contributions.
## Code of Conduct
This project and everyone participating in it is governed by the [DsacJs Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
## Authors
- [Gabriel Logan](https://github.com/gabriel-logan/)

@@ -0,5 +1,35 @@

declare class ListNode<T = any> {
value: T;
next: ListNode<T> | null;
prev: ListNode<T> | null;
constructor(value: T);
}
export default class DoublyLinkedList<T = any> {
private readonly logger;
private readonly head;
private addAtIndex;
head: ListNode<T> | null;
tail: ListNode<T> | null;
size: number;
constructor();
add(value: T): void;
add(index: number, value: T): void;
addFirst(value: T): void;
addLast(value: T): void;
clear(): void;
contains(value: T): boolean;
get(index: number): T | null;
getFirst(): T | null;
getLast(): T | null;
indexOf(value: T): number;
iterator(): IterableIterator<T>;
isEmpty(): boolean;
peek(): T | null;
poll(): T | null;
print(): void;
printReverse(): void;
removeAt(index: number): T | null;
removeFirst(): T | null;
removeLast(): T | null;
toArray(): T[];
}
export {};
export default class Queue<T = any> {
private readonly list;
constructor();
clear(): void;
dequeue(): T | null;
enqueue(value: T): void;
dequeue(): T | null;
isEmpty(): boolean;
peek(): T | null;
isEmpty(): boolean;
print(): void;
size(): number;
print(): void;
clear(): void;
}

@@ -8,2 +8,3 @@ declare class ListNode<T = any> {

private readonly logger;
private addAtIndex;
head: ListNode<T> | null;

@@ -13,12 +14,21 @@ tail: ListNode<T> | null;

constructor();
add(value: T): void;
add(index: number, value: T): void;
addFirst(value: T): void;
addLast(value: T): void;
clear(): void;
getFirst(): T | null;
getLast(): T | null;
indexOf(value: T): number;
isEmpty(): boolean;
peek(): T | null;
addFirst(value: T): void;
addLast(value: T): void;
poll(): T | null;
print(): void;
printReverse(): void;
remove(value: T): boolean;
removeAt(index: number): T | null;
removeFirst(): T | null;
removeLast(): T | null;
print(): void;
printReverse(): void;
clear(): void;
toArray(): T[];
}
export {};
export default class Stack<T = any> {
private readonly list;
constructor();
clear(): void;
isEmpty(): boolean;
peek(): T | null;
pop(): T | null;
print(): void;
push(value: T): void;
pop(): T | null;
peek(): T | null;
isEmpty(): boolean;
size(): number;
print(): void;
clear(): void;
}

@@ -1,2 +0,10 @@

import binarySearch from "./Algorithms/binarySearch";
import factorial from "./algorithms/math/factorial";
import binarySearch from "./algorithms/search/binarySearch";
import linearSearch from "./algorithms/search/linearSearch";
import recursiveBinarySearch from "./algorithms/search/recursiveBinarySearch";
import bubbleSort from "./algorithms/sort/bubbleSort";
import insertionSort from "./algorithms/sort/insertionSort";
import mergeSort from "./algorithms/sort/mergeSort";
import quickSort from "./algorithms/sort/quickSort";
import Deque from "./dataStructures/Deque";
import DoublyLinkedList from "./dataStructures/DoublyLinkedList";

@@ -7,2 +15,2 @@ import Queue from "./dataStructures/Queue";

import Logger from "./lib/Logger";
export { SingleLinkedList, Stack, Queue, DoublyLinkedList as LinkedList, Logger, binarySearch, };
export { SingleLinkedList, Stack, Queue, DoublyLinkedList as LinkedList, Deque, Logger, binarySearch, factorial, linearSearch, recursiveBinarySearch, bubbleSort, insertionSort, mergeSort, quickSort, };
export default class Logger {
private readonly prefix;
private readonly colors;
constructor(prefix?: string);

@@ -4,0 +5,0 @@ log(data: any): void;

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