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

dsacjs

Package Overview
Dependencies
Maintainers
1
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.1-test to 0.0.1

dist/Algorithms/math/factorial.js

167

dist/dataStructures/SingleLinkedList.js

@@ -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,9 +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);
}
}
prepend(value) {
addFirst(value) {
const newNode = new ListNode(value);
if (this.isEmpty()) {
this.head = newNode;
this.tail = newNode;

@@ -33,20 +64,120 @@ }

newNode.next = this.head;
this.head = newNode;
}
this.head = newNode;
this.size++;
}
append(value) {
addLast(value) {
const newNode = new ListNode(value);
if (this.isEmpty()) {
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() {

@@ -90,16 +221,12 @@ var _a, _b, _c;

}
print() {
if (this.isEmpty()) {
return this.logger.info("List is empty");
}
toArray() {
let current = this.head;
let listValues = "";
const listValues = [];
while (current) {
listValues += `${current.value} -> `;
listValues.push(current.value);
current = current.next;
}
listValues += "null";
this.logger.info(listValues);
return listValues;
}
}
exports.default = SingleLinkedList;

@@ -6,4 +6,30 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.SingleLinkedList = void 0;
exports.Deque = exports.quickSort = exports.mergeSort = exports.insertionSort = exports.bubbleSort = exports.recursiveBinarySearch = exports.linearSearch = exports.factorial = exports.binarySearch = exports.Logger = 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"));
exports.LinkedList = DoublyLinkedList_1.default;
const Queue_1 = __importDefault(require("./dataStructures/Queue"));
exports.Queue = Queue_1.default;
const SingleLinkedList_1 = __importDefault(require("./dataStructures/SingleLinkedList"));
exports.SingleLinkedList = SingleLinkedList_1.default;
const Stack_1 = __importDefault(require("./dataStructures/Stack"));
exports.Stack = Stack_1.default;
const Logger_1 = __importDefault(require("./lib/Logger"));
exports.Logger = Logger_1.default;

36

dist/lib/Logger.js

@@ -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.1-test",
"version": "0.0.1",
"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": {

@@ -13,0 +16,0 @@ "test": "jest --verbose",

@@ -1,5 +0,83 @@

# DsacJs - Data Structures - Algorithm - Toolkit Collection
# IN DEVELOPMENT
# 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)
## 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/)

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

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

@@ -13,9 +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;
prepend(value: T): void;
append(value: T): void;
peek(): T | null;
poll(): T | null;
print(): void;
printReverse(): void;
remove(value: T): boolean;
removeAt(index: number): T | null;
removeFirst(): T | null;
removeLast(): T | null;
print(): void;
toArray(): T[];
}
export {};

@@ -0,2 +1,15 @@

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";
import Queue from "./dataStructures/Queue";
import SingleLinkedList from "./dataStructures/SingleLinkedList";
export { SingleLinkedList };
import Stack from "./dataStructures/Stack";
import Logger from "./lib/Logger";
export { SingleLinkedList, Stack, Queue, DoublyLinkedList as LinkedList, Logger, binarySearch, factorial, linearSearch, recursiveBinarySearch, bubbleSort, insertionSort, mergeSort, quickSort, Deque, };
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