A comprehensive collection of TypeScript utility functions and helpers designed to enhance your development experience. This library provides a treasure trove of powerful, type-safe utilities organized into focused modules for different domains of application development.
Choose your preferred package manager:
npm install @arcmantle/library
# or
pnpm add @arcmantle/library
# or
yarn add @arcmantle/libraryImport utilities from specific modules to keep your bundle size optimized:
// Import from specific modules
import { debounce, throttle } from '@arcmantle/library/timing';
import { arrayMove, range } from '@arcmantle/library/array';
import { animateTo } from '@arcmantle/library/animation';
import { deepMerge } from '@arcmantle/library/structs';
// Use the utilities
const debouncedHandler = debounce(() => console.log('Hello!'), 300);
const numbers = range(1, 10);
const merged = deepMerge(obj1, obj2);Web animation utilities with accessibility considerations:
animateTo()- Promise-based element animations with keyframesparseDuration()- Parse CSS duration strings to millisecondsprefersReducedMotion()- Respect user accessibility preferencessetDefaultAnimation()/getAnimation()- Animation registry systemanimationSpeed- Global animation speed controls
Powerful array manipulation and utilities:
arrayMove()- Move elements between indicesarrayRemove()/arrayRemoveAt()- Remove elements safelyarraySum()/arrayObjSum()- Sum arrays and object propertieshasSameElements()/hasCommonElement()- Array comparisonfindInstanceOf()- Find instances of specific typesrandomElement()- Get random array elementsswapItems()- Swap array elementsrange()- Generate number rangestuple()- Create strongly-typed tuples
Asynchronous programming helpers:
maybe()- Error-safe promise handling with tuple returnsresolvablePromise()- Create promises with external resolve/rejectwaitForPromises()- Advanced promise coordinationpauseableEvent()- Event handling with pause/resumecachedPromise()- Promise result cachingsleep()/paintCycle()- Timing utilities
Canvas and graphics utilities:
WorkerView- Web Worker-based canvas rendering
Event and communication patterns:
Phenomenon- Type-safe event systemBeholder- Event listener managementHooks- Lifecycle and hook patterns
DOM manipulation and browser APIs:
- Element utilities:
findDocumentOrShadowRoot(),elementHasAncestor() - Scroll management:
lockBodyScrolling(),scrollIntoView(),scrollElementTo() - Events:
emitEvent(),waitForEvent(),setEventHandled() - Focus management:
isTabbable(),getTabbableBoundary(),hasKeyboardFocus() - Browser detection:
isMobile(),isTouch() - Utilities:
copyTextToClipboard(),notification(),storage(),domId() - URL/Search params: Complete search parameter management
- Modal system: Built-in modal management
- Drag system: Drag and drop utilities
Enumeration utilities for better type safety.
Function composition and utility patterns:
bind()/unbind()- Function binding utilitieslazy()- Lazy evaluation patternsnoop()- No-operation functionnameof()- Type-safe property name extractionresolveValueProvider()- Value provider patternimportPicker()- Dynamic import utilities
Browser database management:
IndexDBWrapper- Type-safe IndexedDB abstractionIndexDBSchema- Database schema management- Complete database setup and collection management
Advanced iteration patterns and utilities.
Mathematical utilities:
roundToNearest()- Round numbers to nearest values
Tree data structure utilities:
NodeTree- Complete tree implementationfromSingleObject()/fromMultiObject()/fromList()- Tree creationaugment()- Tree node augmentation- Type-safe tree traversal and manipulation
String manipulation utilities:
uppercaseFirstLetter()- Capitalize first lettercamelCaseToWords()- Convert camelCase to readable wordsremoveSegments()- Remove string segmentstrimPostfix()- Remove string suffixeswordCount()- Count words in textdeIndent()- Remove indentationformat()- String formatting utilities
Data structure utilities and patterns:
- Object utilities:
deepMerge(),clone(),getObjectDiff() - Path utilities:
readPath(),writePath()for nested object access - Collections:
ObservableSet,ObservableMap,MirrorMap - Mixins:
createMixin(),compose(),hasMixin() - Catalogs: Advanced cataloging and usage tracking
- Lazy utilities:
lazyMap(),lazyWeakmap() - Set operations:
setsHaveSameItems(),getEqualItems()
Time-based utilities and performance helpers:
debounce()- Debounce function calls with control methodsthrottle()- Throttle function executionaccurateTimer()- High-precision timing utilities
Comprehensive TypeScript type utilities:
- Record types:
RecordOf,ValueOf,ObjectKeysToUnion - Union types:
UnionToIntersection,UnionToTuple,IsUnion - Utility types:
Mandatory,Optional,Writeable,DeepWriteable - Path types:
Path,PathValue,PathOffor type-safe object paths - Function types:
Fn,AsyncFn,CreatorFn - Data types:
Vec2,Vec3,Json - And many more advanced TypeScript patterns
Runtime validation and type checking:
- Type guards:
isObject(),isPlainObject(),isFunction(),isClass() - JSON utilities:
safeJsonParse(),safeJsonStringify() - Range validation:
isNumberInRange(),isRangeInRanges() - Utilities:
ifDefined(),invariant(),typeOf(),oneOf()
import { debounce } from '@arcmantle/library/timing';
const searchHandler = debounce((query: string) => {
// Perform search
console.log('Searching for:', query);
}, 300);
// The search will only execute 300ms after the user stops typing
searchInput.addEventListener('input', (e) => {
searchHandler(e.target.value);
});import { maybe } from '@arcmantle/library/async';
async function fetchData() {
const [data, error] = await maybe(fetch('/api/data'));
if (error) {
console.error('Failed to fetch:', error);
return;
}
// data is guaranteed to be defined here
console.log('Success:', data);
}import { arrayMove, range, randomElement } from '@arcmantle/library/array';
// Create a range of numbers
const numbers = range(1, 10); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
// Move element from index 0 to index 3
arrayMove(numbers, 0, 3); // [2, 3, 4, 1, 5, 6, 7, 8, 9, 10]
// Get a random element
const lucky = randomElement(numbers);import { readPath, writePath } from '@arcmantle/library/structs';
const user = {
profile: {
name: 'John',
settings: {
theme: 'dark'
}
}
};
// Type-safe path reading
const theme = readPath(user, 'profile.settings.theme'); // 'dark'
// Type-safe path writing
writePath(user, 'profile.settings.theme', 'light');import { animateTo, prefersReducedMotion } from '@arcmantle/library/animation';
const element = document.querySelector('.my-element');
if (!prefersReducedMotion()) {
await animateTo(element, [
{ transform: 'translateX(0px)' },
{ transform: 'translateX(100px)' }
], {
duration: 300,
easing: 'ease-out'
});
}This library is built with TypeScript from the ground up, providing excellent type safety and IntelliSense support. All utilities include comprehensive type definitions and many provide advanced type-level programming features.
Apache-2.0
Kristoffer Roen-Lie