Détail du package

thingies

streamich20.5mMIT2.5.0

Useful TypeScript utilities.

readme

thingies

Useful TypeScript utilities.

Menu

  • base64 — Base64 encoding end decoding functions for Node.js.

  • Cache — implementation of local memory cache for database records. Can cache retrieved database records for few dozen seconds and has garbage collection logic which clears the memory of old items after some time.

  • Defer — an inverted Promise, an object which allows you to imperatively control the behavior of a Promise.

  • @debug — a class method or function decorator, which logs the input and output of the function in non-production environments.

  • hash — a fast and simple utility, which hashes a string to an integer. Useful for generating a shard index of a record based on its ID.

  • LruMap — tiny and fast Least Recently Used Cache implemented on top of the Map class. The default limit is around 1 billion items (2^30 - 1).

  • LruTtlMap — tiny and fast Least Recently Used Cache with expiration timestamp stored for each entry implemented on top of the LruMap class.

  • LruCache — a Least Recently Used Cache implemented using Object and doubly linked list. The default limit is around 1 billion items (2^30 - 1).

  • normalizeEmail — normalizes email by stripping out . and + characters and removing everything after the + character and lower-casing the e-mail. Useful for getting an e-mail into a common form when throttling requests by e-mail.

  • of — returns result of a Promise as a 3-tuple [value, error, isError].

  • promiseMap — maps a list of values to an async function and waits until all results complete execution.

  • randomStr — generates a random string of given size. Alphabet for character picking can be provided. Useful for generating random database record IDs.

  • TimedQueue — a queue which can be flushed manually, or which flushes automatically when the number of queued items reaches a threshold or when a timeout expires since the first item was added to the queue. Useful for batching multiple messages or requests for bulk processing.

  • TimedState — works similar to TimedQueue, but instead of keeping track of all items pushed, it invokes a reducer to update the state with the information from the last pushed item.

  • tick — returns a Promise which resolves after a given number of milliseconds, useful for releasing the event loop for a short period of time, await tick(5).

  • until — waits for some condition to become true await until(() => condition), useful when waiting for some asynchronous task to happen in a test.

  • concurrency — limits the number of concurrent executions of asynchronous code. concurrencyDecorator limits the number of concurrent executions of a class method.

  • codeMutex — a mutex which can be used to synchronize code execution. Code wrapped by this mutex will execute only one at a time, for all parallel calls to the same mutex.

  • @mutex and mutex() — same as codeMutex, but can be used as a decorator or a higher order function.


  • once — a class method decorator, which limits method execution to once per instance. Returns the result of the first execution for all subsequent calls.

  • loadCss — loads a CSS file into the DOM, given a URL. Does nothing on the server.

  • dataUri — converts a string to a data URI.

  • FanOut — a class which allows to fan out a single event to multiple listeners. Useful for implementing event emitters. In just 12 lines of code.

  • createRace — constructs a "race" function, which takes a function as a single argument, the function is executed immediately only if no other function is currently executing. If another function is currently executing, the current function is discarded.

  • xorShift32 — generates random 32-bit integers using the very fast xorshift algorithm. makeXorShift32(seed) returns a function which can be used to generate random numbers.

  • Locks — a lock manager, which allows to acquire an exclusive lock in browser across multiple tabs. Acquires a lock by writing to localStorage for a specific key for a specified duration.

  • hasKeys — returns true if an object has at lest on key.

  • timeout — waits for async code to complete within a given time frame, otherwise throws an error.

License

MIT © Vadim Dalecky.

changelog

2.5.0 (2024-11-01)

Features

  • 🎸 add debug decorator (19a3c19)
  • 🎸 add support for sync functions (a40c08a)

2.4.0 (2024-08-11)

Features

  • 🎸 expose LruCache, add to README, run Prettier (0e0412e)
  • 🎸 implement LruCache (85c28a3)
  • 🎸 improve LRU cache implementation (aa0bfcf)

Performance Improvements

  • ⚡️ add LRU cache benchmarks (be9a9c7)

2.3.0 (2024-08-11)

Bug Fixes

  • 🐛 support undefined item value refresh (2afccbb)

Features

  • 🎸 improve performance in key retrieval (4dd435c)

Performance Improvements

  • ⚡️ use integer as default LRU limit (5b55327)

2.2.0 (2024-08-11)

Bug Fixes

  • 🐛 if set has size, it always has at least one value (123ce39)

Features

  • 🎸 remove extra check at read (3a08a95)

2.1.1 (2024-06-24)

Bug Fixes

  • correct license in package.json (e39aace)

2.1.0 (2024-04-28)

Features

  • 🎸 implement timeout() utility (05c5339)

2.0.0 (2024-04-27)

Features

  • 🎸 release a single es2020 target (87a9fb1)

BREAKING CHANGES

  • 🧨 Produce only es2020 release artifacts

1.21.0 (2024-04-26)

Features

  • 🎸 add hasKeys() utility (570ea5c)

1.20.0 (2024-04-01)

Features

  • 🎸 add Locks implementation (fc8c1d6)
  • 🎸 improve locking interface (171797b)

1.19.3 (2024-03-30)

Bug Fixes

  • 🐛 allow different return type per racer (ffc3b89)

1.19.2 (2024-03-19)

Bug Fixes

  • 🐛 limit mutex scope to a single class instance (c994280)
  • 🐛 make concurrency() decorator apply per class instance (839c898)

Performance Improvements

  • ⚡️ improve once() decorator (c50e19f)

1.19.1 (2024-03-14)

Bug Fixes

  • 🐛 correctly store execution results in once decorator (9c6d49d)

1.19.0 (2024-03-14)

Features

  • 🎸 implement "once" class method decorator (d1434ae)

1.18.0 (2024-03-11)

Features

  • 🎸 implement concurrency() class method decorator (1e00c9e)

1.17.0 (2024-03-09)

Features

  • 🎸 add support for arguments in mutex decorator (7095e93)

1.16.0 (2024-01-13)

Features

  • 🎸 add xosrshift implementation (e32a638)

1.15.0 (2023-12-04)

Features

  • 🎸 add createRace() utility (c835bb2)

1.14.2 (2023-11-25)

Bug Fixes

  • 🐛 make FanOut listeners public (4a7e546)

1.14.1 (2023-11-24)

Bug Fixes

  • 🐛 make .listeners protected (16aed9a)

1.14.0 (2023-11-24)

Features

  • 🎸 add FanOut implementation (018bfb0)

1.13.1 (2023-11-21)

Bug Fixes

  • 🐛 produce build artifacts in release (11a3e77)

1.13.0 (2023-11-20)

Features

  • 🎸 add dataUri() utility (d2784ae)

1.12.0 (2023-07-02)

Features

  • 🎸 add loadCss() method (e44534d)

1.10.1 (2023-04-07)

Bug Fixes

  • 🐛 do not remove comments (201fb98)

1.10.0 (2023-04-07)

Features

1.9.0 (2023-04-07)

Features

  • 🎸 improve codeMutex() interface (cb85955)

1.8.0 (2023-04-07)

Features

1.7.0 (2023-04-05)

Features

  • 🎸 imrprove internal queue type (770ef26)
  • 🎸 use Set as a FIFO queue (2b82a06)

1.6.0 (2023-04-05)

Features

  • 🎸 expose concurrency() from index (6a2450f)

1.5.0 (2023-04-05)

Features

  • 🎸 add concurrency() implementation (c195a31)

1.4.0 (2022-11-02)

Features

  • 🎸 allow async check function in until() (a545be9)

1.3.1 (2022-07-02)

Bug Fixes

  • 🐛 make Cache timers unreffed (0073ac0)

1.3.0 (2022-04-07)

Features

  • 🎸 add index file (2e135f8)
  • 🎸 add tick() and until() methods (caeb0b0)

1.2.0 (2021-11-01)

Features

  • 🎸 implement TimeState utility class (7423a93)

1.1.0 (2021-10-23)

Features

  • 🎸 place LruMap and LruTtlMap into separate files (36c4ba1)

1.0.0 (2021-10-23)

Features

  • 🎸 add batch of utitlities (6fbb893)
  • 🎸 add normalizeEmail() function (7403b9d)
  • 🎸 add of() method (f236dd4)
  • 🎸 add promiseMap() method (ce0dc45)
  • 🎸 add randomStr() function (299d85b)
  • 🎸 add TimedQueue utility (484da32)