npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@btilford/ts-base

v1.1.2

Published

Boring things used in projects.

Downloads

6

Readme

ts-base

Build PR/Master

Boring project components.

Install

npm install --save @btilford/ts-base-node
npm install --save @btilford/ts-base-browser

Usage

Examples can be found here

Features

Logging

Extra features and configurability for logging. By default uses Console but with node can also use a stream.Writable for stdout and stderr output.

  • Configure default LogLevel
  • Configure and register a root Log
  • Log.extend creates a new Log extending it's name and any configuration not overridden.
  • Log.copy creates a new Log instance sharing the configs that were not overridden but does not inherit naming like Log.extend does.
  • You can add Interceptors to your LogConfig to perform additional tasks on log messages. In the node module there is an interceptor for Stackdriver and Datadog that can be combined with a FilterLogMessage to send critical messages.
  • In your LogConfig you can provide a Context function to supply additional properties to make available in a MessageTemplate.
  • You can configure a MessageTemplate and MessageFormat in your LogConfig.
    • MessageTemplate { format(ctx: MessageContext):string } is generates a string that can include items supplied by a Context call.
    • MessageFormat {(msg, ...args):string} can be used to format you log message if you wanted to use something like printj instead of console.log(message, ...args).

| Log Type | Browser | Node | Comment | |--- |--- |--- |--- | | ConsoleLog | yes | yes | Just a wrapper around console | | StdOutLog | no | yes | Uses a Writable defaulting to stdout/stderr | | JsonLog | no | yes | TODO |

APM

There are some method decorators for instrumenting methods with custom APM. The decorators can accept a Filter that can determine whether to run the decorator or just run the original method. For example only run the decorator N times or at intervals.

| Type | System | Provider | |--- |--- |--- | | @Timed | Browser | Console |
| @Timed | Node | Console, StatsD, Prometheus | | @TimedAsync | Browser | Console |
| @TimedAsync | Node | Console, StatsD, Prometheus | | @CountInvocations | Browser | Console |
| @CountInvocations | Node | Console, StatsD, Prometheus | | @CountSuccess | Browser | Console |
| @CountSuccess | Node | Console, StatsD, Prometheus | | @CountErrors | Browser | Console |
| @CountErrors | Node | Console, StatsD, Prometheus | | @GaugeInvocations | Node | Console, StatsD, Prometheus | | @GaugeSuccess | Node | Console, StatsD, Prometheus | | @GaugeErrors | Node | Console, StatsD, Prometheus |

Time

Note most of the things in this package use BigInt which isn't super well supported yet.

Classes

  • TimeMeasurement -- Holds a bigint of arbitrary nanoseconds.
  • Duration -- Holds a bigint representing time elapsed between 2 arbitrary nano seconds.
  • Instant -- Holds a bigint of nanoseconds representing a point in time.
  • Period -- Holds a bigint of elapsed nanoseconds between 2 Instants.

Utilities

  • timePart(nanos, unit) -- Returns the count of unit in nanos and the remainder. [count:bigint, remainder:bigint]
  • timeParts(nanos, parts:{name:string, unit:bigint}[]) -- Returns a Record<string, bigint> with the count for each name based on the remainder of larger units.
  • millisAsString(nanos:bigint, postfix?: '' | 'n') -- Turn nanoseconds into a string... Lots of things don't serialize bigint yet.
  • millisAsNanoString(milliseconds:number, postfix?: '' | 'n') -- Turn milliseconds into a string with all the extra 0s for a nanosecond.

Other Stuff

  • Providers -- A service locator/lookup utility.
  • Env -- Load and access environmental configs with support for nested EnvProps configs based on a prefix. There are loaders for:
    • processEnvLoader -- For process.env on node.
    • loadEnvWithObj -- For providing arbitrary variables.
    • documentQueryExtractor -- For loading data from the DOM in the browser.
    • loadEnvWithMetaTags -- For loading meta tags with a specific prefix in the browser.
    • debugEnv -- Initializes internal components to full debug.
  • PropEnabled -- Matches keys in an EnvProps against a set of accepted values.
  • bootstrap() -- Helper can be called from your entry point to initialize the different components you want to use.