@burnsred/defaults
v1.0.1
Published
> **⚠️ DEPRECATED**: This package is deprecated and will no longer receive updates.
Readme
Defaults
⚠️ DEPRECATED: This package is deprecated and will no longer receive updates.
Deprecation Notice
This package has been deprecated as of version 1.0.0 and is no longer maintained.
What this means:
- No new features will be added
- No bug fixes will be provided
- Security vulnerabilities will not be patched
Recommended Action: Please migrate to alternative solutions as soon as possible.
Support
For questions about this deprecation, please open an issue in the main repository.
Last maintained version: 1.0.0 Deprecation date: February 2026
A system for providing project-wide defaults to libraries.
Setup
First, define your defaults object.
This will map lookup keys to any sort of value. It can be nested to help with specialised scoping.
export default {
foo: FooComponent,
routes: {
foo: RoutedFoo,
members: {
foo: SpecialFooComponent,
},
},
}In your code, use the hooks to access them:
- Direct lookup
const foo = useDefault("foo"); // Will return `FooComponent`The lookup key can contain dots, in which case it will drill down into objects.
const foo = useDefault("routes.foo"); // Will return `RoutedFoo`- Defaults Map
Will find the first matching (non-undefined) lookup for each key from its list of lookups.
const foo = useDefaultMap({
foo: ["routes.members.foo", "routes.foo"],
})This will first check for default["routes"]["members"]["foo"], and if that's
undefined, try default["routes"]["foo"], finally resorting to
default["foo"].
- Fill defaults
Use the fallback defaults method to fill absent entries on an object.
const fullProps = useFillDefaults(props, defaultsMap);
Any keys from defaultsMap that are not present in props will be resolved as
with useDefaultMap.
- Scoped lookup
All of the above hooks acception an optional scope argument.
This can be useful to, for instance, provide a typed default proxy for lookups within a certain section of the defaults object:
function useDefaultWidget(key: string): Widget {
return useDefault(key, 'widgets') as Widget;
}