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/library
Import 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);
@arcmantle/library/animation
)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@arcmantle/library/array
)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@arcmantle/library/async
)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@arcmantle/library/canvas
)Canvas and graphics utilities:
WorkerView
- Web Worker-based canvas rendering@arcmantle/library/coms
)Event and communication patterns:
Phenomenon
- Type-safe event systemBeholder
- Event listener managementHooks
- Lifecycle and hook patterns@arcmantle/library/dom
)DOM manipulation and browser APIs:
findDocumentOrShadowRoot()
, elementHasAncestor()
lockBodyScrolling()
, scrollIntoView()
, scrollElementTo()
emitEvent()
, waitForEvent()
, setEventHandled()
isTabbable()
, getTabbableBoundary()
, hasKeyboardFocus()
isMobile()
, isTouch()
copyTextToClipboard()
, notification()
, storage()
, domId()
@arcmantle/library/enum
)Enumeration utilities for better type safety.
@arcmantle/library/function
)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@arcmantle/library/indexdb
)Browser database management:
IndexDBWrapper
- Type-safe IndexedDB abstractionIndexDBSchema
- Database schema management@arcmantle/library/iterators
)Advanced iteration patterns and utilities.
@arcmantle/library/math
)Mathematical utilities:
roundToNearest()
- Round numbers to nearest values@arcmantle/library/node-tree
)Tree data structure utilities:
NodeTree
- Complete tree implementationfromSingleObject()
/ fromMultiObject()
/ fromList()
- Tree creationaugment()
- Tree node augmentation@arcmantle/library/string
)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@arcmantle/library/structs
)Data structure utilities and patterns:
deepMerge()
, clone()
, getObjectDiff()
readPath()
, writePath()
for nested object accessObservableSet
, ObservableMap
, MirrorMap
createMixin()
, compose()
, hasMixin()
lazyMap()
, lazyWeakmap()
setsHaveSameItems()
, getEqualItems()
@arcmantle/library/timing
)Time-based utilities and performance helpers:
debounce()
- Debounce function calls with control methodsthrottle()
- Throttle function executionaccurateTimer()
- High-precision timing utilities@arcmantle/library/types
)Comprehensive TypeScript type utilities:
RecordOf
, ValueOf
, ObjectKeysToUnion
UnionToIntersection
, UnionToTuple
, IsUnion
Mandatory
, Optional
, Writeable
, DeepWriteable
Path
, PathValue
, PathOf
for type-safe object pathsFn
, AsyncFn
, CreatorFn
Vec2
, Vec3
, Json
@arcmantle/library/validation
)Runtime validation and type checking:
isObject()
, isPlainObject()
, isFunction()
, isClass()
safeJsonParse()
, safeJsonStringify()
isNumberInRange()
, isRangeInRanges()
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