diff options
| author | Bobby <[email protected]> | 2026-04-22 07:04:29 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-04-22 07:04:29 +0530 |
| commit | 9f0c3b0341d3ad29f3201d56fff5f19662a6f0b6 (patch) | |
| tree | e53e1adb1a87b8a0faa4ee9a808155c21c0ab83c /utils/assert/assert.ts | |
| parent | 4dfbf7a13120b3b64521fce6de7d5d3f76cd2084 (diff) | |
| download | hollowdark-9f0c3b0341d3ad29f3201d56fff5f19662a6f0b6.tar.xz hollowdark-9f0c3b0341d3ad29f3201d56fff5f19662a6f0b6.zip | |
Use relative imports for same-directory siblings; split utils into folders
Two related cleanups landed together because they touch the same pattern:
1. Intra-module imports now use relative paths rather than the module's
own path alias. rng/seeded.ts imports from './derive', not 'rng/derive';
time/gameTime.ts from './calendar', not 'time/calendar'; the utils
barrel from './result' etc. This matches rules/01-code-style.md:
"Relative imports only for same-directory siblings." The alias form
is reserved for imports *between* modules — how external callers refer
to a module's public surface.
(The TS language server in the IDE had trouble resolving the self-
aliased form even though svelte-check accepted it; this change
removes the ambiguity.)
2. utils/ is now folder-per-concept. Each utility owns a directory with
its files broken up into small pieces:
utils/result/ types, constructors, predicates, map, unwrap
utils/assert/ assert, assert-never, assert-defined
utils/equal/ deep
utils/types/ brand, deep-readonly, element-of, json, non-empty-array
utils/log/ log
utils/index.ts re-exports from each subfolder via the barrel. External
callers import from 'utils' unchanged; internal references are relative.
One reason to prefer folders over flat files here is headroom — when a
concept grows, new files sit alongside their siblings inside the
concept's folder rather than crowding the utils/ root.
No API changes. All 128 tests still green.
Diffstat (limited to 'utils/assert/assert.ts')
| -rw-r--r-- | utils/assert/assert.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/utils/assert/assert.ts b/utils/assert/assert.ts new file mode 100644 index 0000000..1fd70c8 --- /dev/null +++ b/utils/assert/assert.ts @@ -0,0 +1,10 @@ +/** + * Throw if a condition is false, narrow the type to truthy otherwise. + * For programmer errors (invariants that should never fail); use + * Result<T, E> for recoverable failures. + */ +export function assert(condition: unknown, message?: string): asserts condition { + if (!condition) { + throw new Error(message ?? 'Assertion failed') + } +} |
