open-index/open-npm huggingface dataset:
npm package: @popovmp/read-json
Description: Reads and parses a JSON file. Supports ASCII, UTF8, UTF16, BOM
Latest version: 1.2.0

# Read Json

Reads and parses a JSON file.

No dependencies.

## Supported formats

* Encoding: ANSI, UTF8, UTF16 LE
* BOM - supports files with a UTF BOM record

## Usage

```JavaScript
const {readJson} = require("@popovmp/read-json);

const obj = readJson("path/to/file.json");
```

## Examples

Reading `{"foo": 42}` from various encodings:

```
Encoding: ansi        , data: {"foo": 42}            , json: {"foo":42}
Encoding: utf8        , data: {"foo": 42}            , json: {"foo":42}
Encoding: utf8-bom    , data: ???{"foo": 42}         , json: {"foo":42}
Encoding: utf16-le-bom, data: ??{ " f o o " :   4 2 }, json: {"foo":42}
```

Reading `{"hello":"Свят"}` from various encodings:

```
Encoding: utf8        , data: {"hello": "????????"}               , json: {"hello":"Свят"}
Encoding: utf16-le-bom, data: ??{ " h e l l o " :   " !?2?O?B?" } , json: {"hello":"Свят"}
```
npm package: @popovmp/req-log
Description: Simple and fast request logger for express
Author: Popov MP
Latest version: 1.0.1

# Request Logger for Express

Simple request logger for `express`.

## Usage

```js
const { reqLog } = require('@popovmp/req-log')

app.use( reqLog() ) // app is an express application
```

`req-log` prints stats for the requests in columns as follows:

  - HTTP status code: `200, 304, 404, 500, ...`
  - Request verb: `POST, GET, HEAD, ...`
  - Request time in milliseconds or seconds: `22, 1.3s`
  - The transaction size. It prints the response size on `GET` and the request size on `POST`
  - The path

![req-log](https://image-holder.forexsb.com/store/req-log.png)

## API

You can use `reeq-log` without parameters to print all requests.

```js
app.use( reqLog() )
```

Yuo can also add as a parameter the list of paths you want to ignore for logging.

```js
app.use( reqLog( ['favicon.ico', 'ignore/path-1', 'ignore/path-2'] ))
```

## license

MIT
npm package: @popovmp/request-parser
Description: Request parsing helper
Latest version: 1.3.0

# Request Parser

Helper functions to parse and validate request data.

### Parse URL path parameters

```function parsePathParams(path, template)```

It matches the URL path with a template and returns the path parameters.

Supported types:
 - `:`    - alphanumeric, "-" and "_"
 - `w:`   - alphanumeric and "_" (word characters)
 - `d:`   - digits
 - `b:`   - boolean
 - `b64:` - base64
 - `*:`   - any except "/". It decodes the parameter to a string.

```javascript
import {parsePathParams} from "@popovmp/request-parser";

const path = "/users/trial/true/42";
const template = "/users/:kind/b:isTrial/d:count";

const pathParams = parsePathParams(path, template);

console.log(pathParams); // { kind: "trial", isTrial: true, count: 42 }
```

### Parse request body

```function parseRequestBody(body, contentType)```

It parses the request body based on the content type.

```javascript
import {parseRequestBody} from "@popovmp/request-parser";

const dto    = {hello: "Hello, World!", answer: 42};
const text   = JSON.stringify(dto);
const bytes  = new TextEncoder().encode(text);
const body   = Buffer.from(bytes);

const result = parseRequestBody(body, "application/json");

console.log(result); // { hello: "Hello, World!", answer: 42 }
```

### Parse Form Data

```function parseFormData(formText)```

```javascript
import {parseFormData} from "@popovmp/request-parser";

const formText = "hello=Hello%2C+World%21&answer=42";
const result   = parseFormData(formText);
console.log(result); // { hello: "Hello, World!", answer: 42 }
```

### Parse Query String

```function parseQueryParams(queryText)```

```javascript
import {parseQueryParams} from "@popovmp/request-parser";

const queryText = "hello=Hello%2C+World%21&answer=42";
const result    = parseQueryParams(queryText);
console.log(result); // { hello: "Hello, World!", answer: 42 }
```

### Parse JSON value

```function parseValue(valueText)```

```javascript
import {parseValue} from "@popovmp/request-parser";

const valueText = "42";
const result    = parseValue(valueText);
console.log(result); // 42
```
### Split Authorization Header

```function splitAuthToken(authorization, split, partsCount)```

```javascript
import {splitAuthToken} from "@popovmp/request-parser";

const authorization = "Bearer foo;bar;42";

const [header, payload, signature] = splitAuthToken(authorization, ";", 3);

console.log(header);    // "foo"
console.log(payload);   // "bar"
console.log(signature); // "42"
```
npm package: @popovmp/sha256
Description: HMAC SHA-256 Base64 URL Safe encoding for NodeJS
Latest version: 1.0.2

# HMAC SHA-256 for NodeJS

Encodes a string to a SHA-256 Base64 URL safe string

```javascript
import {encodeSha256} from "@popovmp/sha256";

const text = "Hello, World!";
const key  = "42";

const encodedData = await encodeSha256(text, key);
console.log(encodedData); //=> HLP82ulAwIfz_gRho0jGemRzRJbl7muEwqMmaDaXggI
```
npm package: @popovmp/tar
Description: Creates or extract TAR archives in Nodejs without dependencies.
Author: Popov
Latest version: 1.2.1

# tar

A Nodejs utility for creating and extracting __tar__ archives programmatically.

## Purpose

To be used programmatically for creating and extracting updates in tar format.

The created tar can be compressed or decompressed by the Nodejs zlib. 

__tar__ create archive in `POSIX 1003.1-1988 (ustar)` format.

## Goals

- to create and extracts __tar__ archives in __UStar__ format.
- to be compatible with __7-Zip__ and the Linux __tar__  command.
- to have an easy, eat all, API.
- to have a more detailed API for hacking.
- use relative paths from the parent of the 'target' directory

## Examples

### Tar all

Archive a complete directory to a tar archive.

Here `target` can be a path to a directory or a single file. 

```JavaScript
const {createArchive} = require("@popovmp/tar");

const tarPath = "stuff.tar";
const target  = "./path/to/stuff";

createArchive(tarPath, target);
```

### Extract all

Extract a __tar__ archive from `tarPath` into the `destination` directory. 

```JavaScript
const {extractArchive} = require("@popovmp/tar");

const tarPath     = "stuff.tar";
const destination = "./destination";

extractArchive(tarPath, destination);
```

### Extract a Buffer

You can extract a __tar__ buffer to a destination directory.
This method is useful when you acquire the tar buffer from a network request.

```JavaScript
const {extract} = require("@popovmp/tar");

const tarball     = getTarBufferSomehow();
const destination = "./destination";

extract(tarball, destination);
```

### Create tar by entry paths

Create a __tar__ Buffer given a list of entry paths and a base directory.

This is useful if you want to precise the tar content. 

```JavaScript
const {getEntryStats, create} = require("@popovmp/tar");
const {gzipSync} = require("node:zlib");

const baseDir    = "./base";
const entryPaths = [
	"stuff/",
	"stuff/hello.txt",
	"stuff/inner/",
	"stuff/inner/other.bin",
];

const entryStats = getEntryStats(baseDir, entryPaths);
const tarball    = create(baseDir, entryStats);
const tarGz      = gzipSync(tarball);

// Save tarGz to file or send it via network.
```

### Get entry paths

Read all entry pats of a target directory.

It is useful if you want to manually add or remove paths to archive.

```JavaScript
const {getEntryPaths} = require("@popovmp/tar");

const target     = "./path/to/stuff";
const entryPaths = getEntryPaths(target);

console.log(entryPaths.join("\n"));    

/* 
"stuff/"
"stuff/hello.txt"
"stuff/inner/"
"stuff/inner/other.bin"
*/
```
npm package: @popovmp/tokenizer
Description: Tokenizer of c-like languages.
Author: Popov
Latest version: 2.1.0

# Tokenizer of a C-like languages

A **Token** is a structure with the following properties:

```js
/**
 * @typedef {Object} Token
 *
 * @property {number}    line
 * @property {number}    column
 * @property {TokenType} type
 * @property {string}    value
 */
```

## Methods

```js
/**
 * @typedef {Object} TokenizerOptions
 *
 * @property {string[]} [keywords]
 * @property {string[]} [operators]
 * @property {string[]} [punctuations]
 */

/**
 * Tokenizes source code
 *
 * @param {string} sourceCode
 * @param {TokenizerOptions} options
 *
 * @return {Token[]}
 */
function tokenize(sourceCode, options) { }


/**
 * Stringifies tokens back to a source code
 *
 * @param {Token[]} tokens
 *
 * @return {string}
 */
function stringify(tokens) { }


/**
 * Removes meaningless tokens as: space, eol, comment
 *
 * @param {Token[]} tokens
 *
 * @return {Token[]}
 */
function clean(tokens) { }
```

## Examples

```c
#include <stdio.h>

int main()
{
    printf("Hello, World!\n");
}
```

```json
[
  {"line":0,"column":0,"type":"pragma","value":"include"},
  {"line":0,"column":0,"type":"space","value":" "},
  {"line":0,"column":1,"type":"operator","value":"<"},
  {"line":0,"column":2,"type":"word","value":"stdio"},
  {"line":0,"column":7,"type":"operator","value":"."},
  {"line":0,"column":8,"type":"word","value":"h"},
  {"line":0,"column":9,"type":"operator","value":">"},
  {"line":0,"column":10,"type":"eol","value":"\n\n"},
  {"line":2,"column":0,"type":"keyword","value":"int"},
  {"line":2,"column":3,"type":"space","value":" "},
  {"line":2,"column":4,"type":"word","value":"main"},
  {"line":2,"column":8,"type":"punctuation","value":"("},
  {"line":2,"column":9,"type":"punctuation","value":")"},
  {"line":2,"column":10,"type":"eol","value":"\n"},
  {"line":3,"column":0,"type":"punctuation","value":"{"},
  {"line":3,"column":1,"type":"eol","value":"\n"},
  {"line":4,"column":0,"type":"space","value":"    "},
  {"line":4,"column":4,"type":"word","value":"printf"},
  {"line":4,"column":10,"type":"punctuation","value":"("},
  {"line":4,"column":11,"type":"string","value":"Hello, World!\n"},
  {"line":4,"column":27,"type":"punctuation","value":")"},
  {"line":4,"column":28,"type":"punctuation","value":";"},
  {"line":4,"column":29,"type":"eol","value":"\n"}
]
```