Catalog npm
Back to packageRELEASE DETAILS

0.0.2

npm

@0bdx/semi-parser

A collection of tools for roughly (but quickly) parsing CSS, HTML and JavaScript

jsparseredact
Published24 Jan 2023
Direct dependencies1
Transitive dependenciesNot calculated

README

Current package documentation

semi-parser

A collection of tools for roughly (but quickly) parsing CSS, HTML and JavaScript.

∅  Version: 0.0.6
∅  NPM: https://www.npmjs.com/package/@0bdx/semi-parser
∅  Repo: https://github.com/0bdx/semi-parser
∅  Homepage: https://0bdx.com/semi-parser

@TODO add an overview


Installation

npm i @0bdx/semi-parser

Require an LTS Node version (v14.0.0+).

Usage

@TODO add the redactJs() description

import { equal } from 'assert';
import { redactJs } from '@0bdx/semi-parser';

// In this JavaScript source code, we'd like to replace the identifier
// `foo` with `ok`, without changing the comment, or the string 'foo',
const source = `let foo = 'foo'; console.log(foo); // displays "foo"`;
console.log(`source:\n    ${source}`);

// Define a simple regular expression which finds "foo" multiple times.
// The `g` flag makes exec() search repeatedly - tinyurl.com/mr2puud2
const rx = /foo/g;

// "foo" appears four times in `source`, ending at 7, 14, 32 and 51.
const endPositions = [];
while (rx.exec(source)) endPositions.push(rx.lastIndex);
equal(endPositions.join(), '7,14,32,51');

// Fill the string with dashes, and replace the comment with spaces.
const result = redactJs(source); // no 2nd argument, so default options
equal(result, "let foo = '---'; console.log(foo);                  ");

// "foo" only appears twice in `result`, ending at positions 7 and 32.
// Fill an array with the parts of `source` which do not contain "foo".
let parts = [], from = 0;
while (rx.exec(result)) {
    const endPos = rx.lastIndex;
    parts.push(source.slice(from, endPos - 3)); // 'foo' length is 3
    from = endPos;
}
parts.push(source.slice(from)); // the part after the final "foo"

// Join the parts into a string, with 'ok' placed between each part.
const replaced = parts.join('ok');
equal(replaced, `let ok = 'foo'; console.log(ok); // displays "foo"`);
console.log(`replaced:\n    ${replaced}`);

You can find the redactJs() example in the src/redact-js/ directory, and run it using:
npm run example-1


Contributing

Set up your development machine

  1. Check your Git version:
    git --version # should be 'git version 2.20.1' or greater
  2. Check your Node version:
    node --version # should be 'v14.0.0' or greater
  3. Check your global TypeScript version:
    tsc --version # should be 'Version 4.9.4' or greater
    There are no actual .ts files in this project, but TypeScript can infer types from the JavaScript code and JSDoc comments.
    • VS Code uses tsserver to highlight errors in src/ JavaScript files
    • tsc is needed to generate the semi-parser.d.ts type declaration

Set up VS Code

  1. Check your VS Code version:
    code --version # should be '1.74.3' or greater
  2. Install and enable the jeremyljackson.vs-docblock extension.
  3. Install and enable the dnamsons.kimbie-dark-plus theme.

Set up the repo locally

Clone the repository, and cd into it.
git clone git@github.com:0bdx/semi-parser.git && cd semi-parser

Install Rollup, the only dependency.
npm i
Rollup 3.10.1 adds 2 packages, 2.5 MB, 29 items.

Open semi-parser in VS Code.
code .

Handy dev commands

Run all tests on the in-development source code:
npm test

Run each example, one by one:
npm run example:1
npm run example:2

Or run all the examples:
npm run examples

Build semi-parser.js and semi-parser.d.ts:
npm run build:production
npm run build:typings

Run all tests on the built semi-parser.js file:
npm run preflight:test

Check that semi-parser.js uses all types correctly:
npm run preflight:types

Or run all the build and preflight steps in one line, eg before committing:
npm run build && npm run preflight

Display what will be published:
npm publish --dry-run

Publish to npmjs.com/package/@0bdx/semi-parser:
npm publish

Downloads & popularity

2downloads
7-day window · source-reported counts21 Oct 2026
210
2026-10-21: 2 · observed 2026-10-21T15:14:28.2521840Z
21 Oct21 Oct

npm · 1 observations shown. Missing days are unknown.

View observed values
Date / source periodValueObserved at
2026-10-2122026-10-21T15:14:28.2521840Z

Declared dependencies 1

Native requirements
1 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
rollup
Environment
{
  "local_name": "rollup",
  "alias": false,
  "peer_metadata": null
}
^3.10.1development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-4gvdLwxWT8eNTIE7gnsmeENE/lQgwYIEn3/pb9QTKNd8evkKeW3vR3WWRIt/osV+dQsYxd/qpLAZiLu9rjVsQw==",
  "shasum": "2960f59bcabf2ae58e8596f3f960daaa1955ddb0",
  "tarball": "https://registry.npmjs.org/@0bdx/semi-parser/-/semi-parser-0.0.2.tgz",
  "fileCount": 4,
  "unpackedSize": 8884,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEYCIQC3SmtmzkIlYvzdY4WTB5t7OYIxx1x5oKB1NFZqhGDm6QIhAMf9FzHwX4lAttmPzL+3hTMLYqFkXm3RYJIikqQNX03b"
    }
  ],
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjz751ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqvFhAAh29HEDFVy4Q7X2ND3bCcQwpXpTkj8ZPLRYMjgTQL1FREybhs\r\nXaklZ1tHN08w7DMgImEpwONEkezLAcTAFgOGJoNI38JqzfPTynhr64URMIPA\r\nf2xUfBepbaeolY7mf1pf1QksZfpUGAWFpfhKzwzNWUyBg5Y7GcQNe3XbSIJs\r\npu7Pb/GZV6Iigl6UlT+DT+5fU9AQ8A2P8lPX6mVrOf7nz0Eqaof93p1BfBA2\r\niFljchNWeUFIenKtG3ka+IFQomKI9dkesLYyHPqRZOITlsnG4r/wOKsWCXDb\r\n23BVznJh2D95VDFwY8P9bBJBeh4LCLTo9/23j0Ulzix3SvBzKXKP9thLl5hg\r\ncaj4Njs+/jPpC4BPktzUIQLnGmAczYBZTfPvNbr2qVuABLvrgpcSkRXmf79s\r\niEc+LBwJGXXkCyqTtQOoVyy4oIW5gFBV7s5DLZM+/Z4SxjdJQoP7LQj53XBQ\r\nCcAAGTJxk2V/uwBD1ZoV33CjancRMqJ7OcDRtmtnBh1JNrenQN1w4s9hHV4I\r\nMmJjQXeR14NpQq/4sy5qcJM1RxBEu/jSA/o1JN8yqAOSm77CZEljaJeoKov5\r\nbgFC06micgaB9a8BVuqd2y81KOBIK5+6T0QQskrznEQTdS8R/Uw5GmHTIKpb\r\n+xoEWIcYwUNQQ/TzsSi+sDSwbWzPjup8/9E=\r\n=PENR\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
0bdx/semi-parser

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:04 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:68912f66bc91e4d7bd8c16c8fd066c355d711babbe3ec7a428c6c4c8a22c517e

Other collected versions

0.0.64 Feb0.0.526 Jan0.0.426 Jan0.0.324 Jan0.0.124 JanView all collected versions →