mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 10:54:44 +00:00
feat(monorepo): migrate vue packages and apply oxlint refactors
This commit is contained in:
@@ -2,21 +2,21 @@
|
||||
* @name flagsGenerator
|
||||
* @category Bits
|
||||
* @description Create a function that generates unique flags
|
||||
*
|
||||
*
|
||||
* @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;
|
||||
let lastFlag = 0;
|
||||
|
||||
return () => {
|
||||
// 31 flags is the maximum number of flags that can be created
|
||||
// (without zero) because of the 32-bit integer limit in bitwise operations
|
||||
if (lastFlag & 0x40000000)
|
||||
throw new RangeError('Cannot create more than 31 flags');
|
||||
return () => {
|
||||
// 31 flags is the maximum number of flags that can be created
|
||||
// (without zero) because of the 32-bit integer limit in bitwise operations
|
||||
if (lastFlag & 0x40000000)
|
||||
throw new RangeError('Cannot create more than 31 flags');
|
||||
|
||||
return (lastFlag = lastFlag === 0 ? 1 : lastFlag << 1);
|
||||
};
|
||||
return (lastFlag = lastFlag === 0 ? 1 : lastFlag << 1);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { and, or, not, has, is, unset, toggle } from '.';
|
||||
|
||||
|
||||
describe('flagsAnd', () => {
|
||||
it('no effect on zero flags', () => {
|
||||
const result = and();
|
||||
@@ -14,7 +13,7 @@ describe('flagsAnd', () => {
|
||||
|
||||
expect(result).toBe(0b1010);
|
||||
});
|
||||
|
||||
|
||||
it('perform bitwise AND operation on flags', () => {
|
||||
const result = and(0b1111, 0b1010, 0b1100);
|
||||
|
||||
@@ -30,15 +29,15 @@ describe('flagsOr', () => {
|
||||
});
|
||||
|
||||
it('source flag is returned if no flags are provided', () => {
|
||||
const result = or(0b1010);
|
||||
|
||||
expect(result).toBe(0b1010);
|
||||
const result = or(0b1010);
|
||||
|
||||
expect(result).toBe(0b1010);
|
||||
});
|
||||
|
||||
it('perform bitwise OR operation on flags', () => {
|
||||
const result = or(0b1111, 0b1010, 0b1100);
|
||||
|
||||
expect(result).toBe(0b1111);
|
||||
const result = or(0b1111, 0b1010, 0b1100);
|
||||
|
||||
expect(result).toBe(0b1111);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,9 +57,9 @@ describe('flagsHas', () => {
|
||||
});
|
||||
|
||||
it('check if a flag has a specific bit unset', () => {
|
||||
const result = has(0b1010, 0b0100);
|
||||
|
||||
expect(result).toBe(false);
|
||||
const result = has(0b1010, 0b0100);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,9 +71,9 @@ describe('flagsIs', () => {
|
||||
});
|
||||
|
||||
it('check if a flag is unset', () => {
|
||||
const result = is(0);
|
||||
|
||||
expect(result).toBe(false);
|
||||
const result = is(0);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -92,4 +91,4 @@ describe('flagsToggle', () => {
|
||||
|
||||
expect(result).toBe(0b0010);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @name and
|
||||
* @category Bits
|
||||
* @description Function to combine multiple flags using the AND operator
|
||||
*
|
||||
*
|
||||
* @param {number[]} flags - The flags to combine
|
||||
* @returns {number} The combined flags
|
||||
*
|
||||
@@ -16,7 +16,7 @@ export function and(...flags: number[]) {
|
||||
* @name or
|
||||
* @category Bits
|
||||
* @description Function to combine multiple flags using the OR operator
|
||||
*
|
||||
*
|
||||
* @param {number[]} flags - The flags to combine
|
||||
* @returns {number} The combined flags
|
||||
*
|
||||
@@ -30,7 +30,7 @@ export function or(...flags: number[]) {
|
||||
* @name not
|
||||
* @category Bits
|
||||
* @description Function to combine multiple flags using the XOR operator
|
||||
*
|
||||
*
|
||||
* @param {number} flag - The flag to apply the NOT operator to
|
||||
* @returns {number} The result of the NOT operator
|
||||
*
|
||||
@@ -44,7 +44,7 @@ export function not(flag: number) {
|
||||
* @name has
|
||||
* @category Bits
|
||||
* @description 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
|
||||
@@ -59,7 +59,7 @@ export function has(flag: number, other: number) {
|
||||
* @name is
|
||||
* @category Bits
|
||||
* @description Function to check if a flag is set
|
||||
*
|
||||
*
|
||||
* @param {number} flag - The flag to check
|
||||
* @returns {boolean} Whether the flag is set
|
||||
*
|
||||
@@ -73,7 +73,7 @@ export function is(flag: number) {
|
||||
* @name unset
|
||||
* @category Bits
|
||||
* @description Function to unset a flag
|
||||
*
|
||||
*
|
||||
* @param {number} flag - Source flag
|
||||
* @param {number} other - Flag to unset
|
||||
* @returns {number} The new flag
|
||||
@@ -88,7 +88,7 @@ export function unset(flag: number, other: number) {
|
||||
* @name toggle
|
||||
* @category Bits
|
||||
* @description Function to toggle (xor) a flag
|
||||
*
|
||||
*
|
||||
* @param {number} flag - Source flag
|
||||
* @param {number} other - Flag to toggle
|
||||
* @returns {number} The new flag
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './flags';
|
||||
export * from './flags';
|
||||
|
||||
@@ -13,7 +13,7 @@ describe('BitVector', () => {
|
||||
it('set and get bits correctly', () => {
|
||||
const bitVector = new BitVector(16);
|
||||
bitVector.setBit(5);
|
||||
|
||||
|
||||
expect(bitVector.getBit(5)).toBe(true);
|
||||
expect(bitVector.getBit(4)).toBe(false);
|
||||
});
|
||||
@@ -40,7 +40,7 @@ describe('BitVector', () => {
|
||||
const indices = [99, 88, 66, 65, 64, 63, 15, 14, 1, 0];
|
||||
const result = [];
|
||||
indices.forEach(index => bitVector.setBit(index));
|
||||
|
||||
|
||||
for (let i = bitVector.previousBit(100); i !== -1; i = bitVector.previousBit(i)) {
|
||||
result.push(i);
|
||||
}
|
||||
@@ -60,4 +60,4 @@ describe('BitVector', () => {
|
||||
|
||||
expect(() => bitVector.previousBit(24)).toThrow(new RangeError('Unreachable value'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ export interface BitVectorLike {
|
||||
* @name BitVector
|
||||
* @category Bits
|
||||
* @description A bit vector is a vector of bits that can be used to store a collection of bits
|
||||
*
|
||||
*
|
||||
* @since 0.0.3
|
||||
*/
|
||||
export class BitVector extends Uint8Array implements BitVectorLike {
|
||||
@@ -58,4 +58,4 @@ export class BitVector extends Uint8Array implements BitVectorLike {
|
||||
|
||||
throw new RangeError('Unreachable value');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user