mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 10:54:44 +00:00
feat(packages): add version jsdoc tags
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
// TODO: tests
|
||||
|
||||
/**
|
||||
* @name _global
|
||||
* @category Multi
|
||||
* @description Global object that works in any environment
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
export const _global =
|
||||
typeof globalThis !== 'undefined'
|
||||
@@ -12,4 +16,4 @@ export const _global =
|
||||
? global
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: {};
|
||||
: undefined;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './global';
|
||||
export * from './debounce';
|
||||
// export * from './debounce';
|
||||
@@ -3,6 +3,8 @@
|
||||
*
|
||||
* @returns {Function} A function that generates unique flags
|
||||
* @throws {RangeError} If more than 31 flags are created
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
export function flagsGenerator() {
|
||||
let lastFlag = 0;
|
||||
@@ -22,6 +24,8 @@ export function flagsGenerator() {
|
||||
*
|
||||
* @param {number[]} flags - The flags to combine
|
||||
* @returns {number} The combined flags
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
export function and(...flags: number[]) {
|
||||
return flags.reduce((acc, flag) => acc & flag, -1);
|
||||
@@ -32,6 +36,8 @@ export function and(...flags: number[]) {
|
||||
*
|
||||
* @param {number[]} flags - The flags to combine
|
||||
* @returns {number} The combined flags
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
export function or(...flags: number[]) {
|
||||
return flags.reduce((acc, flag) => acc | flag, 0);
|
||||
@@ -42,6 +48,8 @@ export function or(...flags: number[]) {
|
||||
*
|
||||
* @param {number} flag - The flag to apply the NOT operator to
|
||||
* @returns {number} The result of the NOT operator
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
export function not(flag: number) {
|
||||
return ~flag;
|
||||
@@ -51,7 +59,10 @@ export function not(flag: number) {
|
||||
* Function to make sure a flag has a specific bit set
|
||||
*
|
||||
* @param {number} flag - The flag to check
|
||||
* @param {number} other - Flag to check
|
||||
* @returns {boolean} Whether the flag has the bit set
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
export function has(flag: number, other: number) {
|
||||
return (flag & other) === other;
|
||||
@@ -62,6 +73,8 @@ export function has(flag: number, other: number) {
|
||||
*
|
||||
* @param {number} flag - The flag to check
|
||||
* @returns {boolean} Whether the flag is set
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
export function is(flag: number) {
|
||||
return flag !== 0;
|
||||
@@ -73,6 +86,8 @@ export function is(flag: number) {
|
||||
* @param {number} flag - Source flag
|
||||
* @param {number} other - Flag to unset
|
||||
* @returns {number} The new flag
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
export function unset(flag: number, other: number) {
|
||||
return flag & ~other;
|
||||
@@ -84,6 +99,8 @@ export function unset(flag: number, other: number) {
|
||||
* @param {number} flag - Source flag
|
||||
* @param {number} other - Flag to toggle
|
||||
* @returns {number} The new flag
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
export function toggle(flag: number, other: number) {
|
||||
return flag ^ other;
|
||||
|
||||
@@ -3,6 +3,8 @@ export type EventsRecord = Record<string, Subscriber>;
|
||||
|
||||
/**
|
||||
* Simple PubSub implementation
|
||||
*
|
||||
* @since 0.0.2
|
||||
*
|
||||
* @template {EventsRecord} Events
|
||||
*/
|
||||
@@ -85,7 +87,7 @@ export class PubSub<Events extends EventsRecord> {
|
||||
* @param {...Parameters<Events[K]>} args Arguments for the listener
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public emit<K extends keyof Events>(event: K, ...args: Parameters<Events[K]>): boolean {
|
||||
public emit<K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) {
|
||||
const listeners = this.events.get(event);
|
||||
|
||||
if (!listeners)
|
||||
|
||||
@@ -4,6 +4,9 @@ export type StackOptions = {
|
||||
|
||||
/**
|
||||
* Represents a stack data structure
|
||||
*
|
||||
* @since 0.0.2
|
||||
*
|
||||
* @template T The type of elements stored in the stack
|
||||
*/
|
||||
export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
|
||||
@@ -13,7 +16,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
private maxSize: number;
|
||||
private readonly maxSize: number;
|
||||
|
||||
/**
|
||||
* The stack data structure
|
||||
@@ -21,7 +24,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
|
||||
* @private
|
||||
* @type {T[]}
|
||||
*/
|
||||
private stack: T[];
|
||||
private readonly stack: T[];
|
||||
|
||||
/**
|
||||
* Creates an instance of Stack
|
||||
@@ -39,7 +42,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
|
||||
* Gets the number of elements in the stack
|
||||
* @returns {number} The number of elements in the stack
|
||||
*/
|
||||
public get length(): number {
|
||||
public get length() {
|
||||
return this.stack.length;
|
||||
}
|
||||
|
||||
@@ -47,7 +50,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
|
||||
* Checks if the stack is empty
|
||||
* @returns {boolean} `true` if the stack is empty, `false` otherwise
|
||||
*/
|
||||
public get isEmpty(): boolean {
|
||||
public get isEmpty() {
|
||||
return this.stack.length === 0;
|
||||
}
|
||||
|
||||
@@ -55,7 +58,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
|
||||
* Checks if the stack is full
|
||||
* @returns {boolean} `true` if the stack is full, `false` otherwise
|
||||
*/
|
||||
public get isFull(): boolean {
|
||||
public get isFull() {
|
||||
return this.stack.length === this.maxSize;
|
||||
}
|
||||
|
||||
@@ -78,7 +81,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
|
||||
* Pops an element from the stack
|
||||
* @returns {T} The element popped from the stack
|
||||
*/
|
||||
public pop(): T | undefined {
|
||||
public pop() {
|
||||
return this.stack.pop();
|
||||
}
|
||||
|
||||
@@ -86,7 +89,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
|
||||
* Peeks at the top element of the stack
|
||||
* @returns {T} The top element of the stack
|
||||
*/
|
||||
public peek(): T | undefined {
|
||||
public peek() {
|
||||
if (this.isEmpty)
|
||||
throw new RangeError('Stack is empty');
|
||||
|
||||
@@ -109,7 +112,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
|
||||
*
|
||||
* @returns {T[]}
|
||||
*/
|
||||
public toArray(): T[] {
|
||||
public toArray() {
|
||||
return this.stack.toReversed();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
* @param {string} left First string
|
||||
* @param {string} right Second string
|
||||
* @returns {number} The Levenshtein distance between the two strings
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
export function levenshteinDistance(left: string, right: string): number {
|
||||
// If the strings are equal, the distance is 0
|
||||
if (left === right) return 0;
|
||||
|
||||
// If either string is empty, the distance is the length of the other string
|
||||
if (left.length === 0) return right.length;
|
||||
if (right.length === 0) return left.length;
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ export type Trigrams = Map<string, number>;
|
||||
*
|
||||
* @param {string} text The text to extract trigrams
|
||||
* @returns {Trigrams} A map of trigram to count
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
export function trigramProfile(text: string): Trigrams {
|
||||
text = '\n\n' + text + '\n\n';
|
||||
@@ -26,6 +28,8 @@ export function trigramProfile(text: string): Trigrams {
|
||||
* @param {Trigrams} left First text trigram profile
|
||||
* @param {Trigrams} right Second text trigram profile
|
||||
* @returns {number} The trigram distance between the two strings
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
export function trigramDistance(left: Trigrams, right: Trigrams): number {
|
||||
let distance = -4;
|
||||
|
||||
Reference in New Issue
Block a user