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

@terascop/rotor

v0.0.7

Published

<!--toc:start--> - [rotor](#rotor) - [Environment](#environment) - [Paradigm](#paradigm) - [Install dependencies](#install-dependencies) - [Lint and format with Biome](#lint-and-format-with-biome) - [Test](#test) - [Compile the CLI to a single

Downloads

1

Readme

rotor

Environment

We use Bun instead of Node.js (runtime) + npm (package manager)

This project was created using bun init in bun v1.1.20.

This was tested only on Linux.

Windows might be OK but is not an official target.

Paradigm

This project is written in TypeScript.

The style is deliberately procedural and functional, with little dependencies.

Install dependencies

bun install

Lint and format with Biome

We use Biome, not ESLint, not Prettier.

# just check :
bun run check
# alias for :
bunx biome check

# check and write safe fixes :
bun run lint
# alias for :
bunx biome check --write

Test

We use Bun's integrated testing feature, not Jest.

It is mostly compatible with Jest syntax.

bun test
# or :
bunx test --watch

Compile the CLI to a single-file executable

See Bun's doc.

Right now the generated bin is quite fat (94MB, gzips to 34MB), but Bun will probably improve this in the future.

It can still be convenient to distribute a single file with zero dependencies, as an alternative to a Docker image.

bun run compile
# alias for :
bun build ./cli.ts --compile --target=bun-linux-x64-modern --sourcemap --outfile ./dist/bin/rotor

See released binaries on the release page.

Package to dist/lib and publish to npm

It transpiles lib.ts to JS with separate .d.ts TypeScript definition files.

bun run bundle
# alias for :
rm -rf ./dist/lib/ \
  && bun build ./lib.ts --target=node --outdir ./dist/lib \
  && tsc --project ./tsconfig.lib.json \
  && cp ./index.d.ts ./dist/lib/

# then :
npm publish --access public

See on @terascop/rotor on npm.

Lib usage

⚠️ TO BE TESTED

npm i @terascop/rotor
import { rotate } from './lib'

await rotate(config)

See config spec in index.d.ts :

export type Pattern = string
export type Limit = number

export type TimeUnit = 'hours' | 'days' | 'weeks' | 'months' | 'years'

export interface Duration {
  unit: TimeUnit
  number: number
}

export interface Window {
  unit: TimeUnit
  sliding?: number | undefined
}

export interface Rule {
  name: string
  span: Duration | null
  limit: Limit
  window: Window | undefined
}

export interface Config {
  dir: string
  patterns: Pattern[]
  ignoreEmptyFiles: boolean
  rules: Rule[]
}

See config example in default.yaml.

See full signature in lib.ts :

/**
 * description: rotates files according to the configuration
 * @param {Date} [now=new Date()] - the reference date for the rotation, defaults to the current date
 * @param {Partial<typeof fsp>} [fspOverride] - overrides for fs.promises methods (readdir, stat, unlink)
 */
export const rotate = async (
  config: Config,
  dryRun = false,
  now: Date = new Date(),
  fspOverride: Partial<typeof fsp> = {},
): Promise<Results> => { ... }

CLI usage

See output of bun ./cli.ts --help :

Options:
      --version       Show version number                              [boolean]
  -p, --dir           Path to the directory containing the files to be rotated.
                      Defaults to config.dir                            [string]
  -i, --ignore-empty  Ignore empty files. Defaults to config.ignoreEmptyFiles
                                                                       [boolean]
      --patterns      Regular expression(s) to match filenames. Defaults to con
                      fig.patterns. Examples:

                      \b(?<unixtimestamp>\d{12,13})\b


                      \b(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})[- _T](?<h
                      our>\d{2})[- :h](?<minute>\d{2})[- :h](?<second>\d{2})[sZ
                      ]?\b

                      ^foobar.\b(?<unixtimestamp>\d{12,13})\b.db.gz.enc$
                                                                         [array]
  -c, --config        Path to config file                               [string]
  -d, --default       Use the default config (subject to change !)
                                                      [boolean] [default: false]
  -e, --example       Display an example config file                   [boolean]
  -t, --dry-run       Perform a dry run (opposite of --apply)
                                                      [boolean] [default: false]
  -a, --apply         Apply the deletions (opposite of --dry-run)
                                                      [boolean] [default: false]
  -s, --colors        Colorize the output             [boolean] [default: false]
  -o, --output        What to output to stdout
  [choices: "list", "summary", "silent", "config-JSON", "config-YAML"] [default:
                                                                         "list"]
      --help          Show help                                        [boolean]