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

mw-replace-bot

v0.4.0

Published

Replacement-focused mediawiki bot

Downloads

18

Readme

mw-replace-bot

A Node.js tool using mediawiki to conveniently perform expressive find-and-replaces on wiki content (including regular expressions with callbacks).

NOTE: This project is very much experimental, and short of the potential it adds for your own replacements to be problematic, it may have its own bugs at this stage. Use at your own risk!

Installation

npm i mw-replace-bot

Usage

In a mw-replace-rc.js file in the same directory as mw-replace-bot, add the following and modify according to your site and replacement needs:

module.exports = {
  // REQUIRED ITEMS

  endpoint: 'https://site-to-be-queried.example/api.php',
  user: 'user@<my-bot-login>',
  password: 'my-bot-password',
  // The search can be more broad than the regex find,
  //   as entries found with `search` that are not found
  //   by `find` will not be modified; but currently a
  //   `search` is needed to get results out of the
  //   API and over the network; the `find` is
  //   post-processing done within Node
  search: 'search terms',

  // This can also be just a string in which case,
  //   regular expressions wouldn't apply and only
  //   a single instance would be replaced
  // For regular expressions in JavaScript, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
  find: /a (regular) expression/gu,

  // Instead of a function, this can also be a
  //   regex replacement string: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter
  // For function docs, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter
  replace (n0, n1) {
    return n1; // Do replacements here
  },

  // OPTIONAL ITEMS
  autoContinue: true,

  // Disable actual editing
  readonly: true,
  // Logging in general
  logging: true,
  // Opt in to show the replaced text of the page in console (can be large)
  logReplacedText: true,
  // Suffix to add to edit summaries:
  byline: '(mw-replace bot edit)',
  // Summary for the batch
  summary: 'A summary for this batch of edits',
  // ms between API requests (Default: 6 secs)
  rate: 6e3,

  // Used in `User-Agent` header; `version` is that of `mediawiki` module
  // 1. Default for Node:
  // 'MediaWiki/' + version + '; Node/' + process.version +
  //    '; <https://github.com/oliver-moran/mediawiki>',
  // 2. Default for browser (once we may support):
  // 'MediaWiki/' + version + '; ' + navigator.userAgent +
  //    '; <https://github.com/oliver-moran/mediawiki>'
  userAgent: 'A string to use for the `User-Agent` header',

  // Continuing
  // Integer
  gsrlimit: 10,
  // One of:
  // "relevance", "just_match", "none", "incoming_links_asc",
  // "incoming_links_desc", "last_edit_asc", "last_edit_desc",
  // "create_timestamp_asc", "create_timestamp_desc"
  gsrsort: 'relevance'
};

To-dos

  1. GUI
  2. Expose a genuine bin script

Lower-priority to-dos

  1. Ideally, update mediawiki to use ES6 Promise API and use here (with await/async)
  2. Client-side browser support (including ESM)
  3. Would ideally tie into SQL to actually do regex search rather than search and then find/replace