Javascript implementation of Nock
Go to file
2024-11-12 10:36:43 -06:00
src atom: handle truncated bytes in fromCord 2024-07-17 00:49:19 -05:00
.gitignore jsbn removed, typescript added, tests running well 2023-09-11 17:34:49 +02:00
.nvmrc initial: imported from urbit/bridge 2022-10-13 14:01:26 -07:00
package-lock.json atom: handle truncated bytes in fromCord 2024-07-17 00:49:19 -05:00
package.json ops: version bump 2024-11-12 10:36:43 -06:00
pnpm-lock.yaml ops: update package 2024-05-14 11:33:15 -05:00
README.md docs: add tiny usage description, warning, comment 2024-01-16 21:09:07 +01:00
TODO initial: imported from urbit/bridge 2022-10-13 14:01:26 -07:00
tsconfig.json jsbn removed, typescript added, tests running well 2023-09-11 17:34:49 +02:00

nockjs

A Javascript implementation of Nock.

Install

npm install @urbit/nockjs

Usage

Presently, primarily for dealing with nouns as Javascript objects.

  • A Noun is an Atom or a Cell.
  • Atom.fromString('123', 10), Atom.fromInt(123), Atom.fromCord('{') all create a new Atom object. Uses bigint internally, can construct with new Atom(someBigint).
  • new Cell(a, b).
  • dwim(...) does a best-effort attempt of interpreting the arguments into a Noun.
  • enjs contains Noun => Json conversions and conversion builders.
  • dejscontains Json => Noun conversions for idiomatic noun shapes.

Immutability

When working with Noun objects, it is important to treat them as immutable, and not assign to their properties or otherwise modify them directly. The TypeScript readonly property should prevent you from doing so, and you must not ignore this.

This library implements unifying equality, deduplicating identical nouns in memory whenever they are detected. This means that one Noun object might be a sub-noun to many other Nouns, and changing the one sub-noun could change it for all nouns it is used in. Additionally, the Noun object keeps a mug cache, which does not get cleared when illicitly changing the noun's contents.