open-index/open-npm huggingface dataset:
npm package: @minikit/arith
Description: Perform addition, subtraction, multiplication and division operations precisely using javascript
Author: Billgo
Latest version: 0.2.0

# @minikit/arith

Perform addition, subtraction, multiplication and division operations precisely using javascript

### Why

```js
0.1 + 0.2 = 0.30000000000000004
1.0 - 0.9 = 0.09999999999999998
0.105.toFixed(2) = 0.1 // not 0.11
```

### Install

```
npm install @minikit/arith --save
```

### Methods

```js
arith.strip(num)         // strip a number to nearest right number
arith.plus(num1, num2, num3, ...)   // addition, num + num2 + num3, two numbers is required at least.
arith.minus(num1, num2, num3, ...)  // subtraction, num1 - num2 - num3
arith.multip(num1, num2, num3, ...)  // multiplication, num1 * num2 * num3
arith.divide(num1, num2, num3, ...) // division, num1 / num2 / num3
arith.round(num, ratio)  // round a number based on ratio
```

### Usage

```js
import arith from "@minikit/arith";
arith.strip(0.09999999999999998); // = 0.1
arith.plus(0.1, 0.2); // = 0.3, not 0.30000000000000004
arith.plus(2.3, 2.4); // = 4.7, not 4.699999999999999
arith.minus(1.0, 0.9); // = 0.1, not 0.09999999999999998
arith.multip(3, 0.3); // = 0.9, not 0.8999999999999999
arith.multip(0.362, 100); // = 36.2, not 36.199999999999996
arith.divide(1.21, 1.1); // = 1.1, not 1.0999999999999999
arith.round(0.105, 2); // = 0.11, not 0.1
```

PS: If you want to get rid of `XXX is beyond boundary when transfer to integer, the results may not be accurate`, use this at the beginning of your app to turn off boundary checking.

```js
arith.enableBoundaryChecking(false); // default param is true
```

### License

MIT
npm package: @minikit/array
Description: Immutable Array prototype methods.
Author: Billgo
Latest version: 0.2.0

# @minikit/array

Immutable Array prototype methods.

- TypeScript
- Small and Thin
  - `@minikit/array` that includes all methods: ~500bytes(gzip+minify)
- Same usage with native `Array.prototype` methods

## Getting Started

```bash
# install dependencies
bun add @minikit/array
```

## Usage

`@minikit/array` is a collection of immutable `Array.prototype` methods.

Basically, the usage of these method is same with mutable version.

```js
import { sort, unshift, push, fill, splice, pop, reverse, copyWithin, shift } from "@minikit/array";

describe("prototype", () => {
  it("shift", () => {
    assert.deepStrictEqual(shift(["a", "b", "c", "d", "e"]), ["b", "c", "d", "e"]);
  });
  it("unshift", () => {
    assert.deepStrictEqual(unshift(["a", "b", "c", "d", "e"], "x"), ["x", "a", "b", "c", "d", "e"]);
  });
  it("pop", () => {
    assert.deepStrictEqual(pop(["a", "b", "c", "d", "e"]), ["a", "b", "c", "d"]);
  });
  it("push", () => {
    assert.deepStrictEqual(push(["a", "b", "c", "d", "e"], "x"), ["a", "b", "c", "d", "e", "x"]);
  });
  it("splice", () => {
    assert.deepStrictEqual(splice(["a", "b", "c", "d", "e"], 0, 1, "x"), ["x", "b", "c", "d", "e"]);
  });
  it("sort", () => {
    assert.deepStrictEqual(sort(["e", "a", "c", "b", "d"]), ["a", "b", "c", "d", "e"]);
  });
  it("reverse", () => {
    assert.deepStrictEqual(reverse(["a", "b", "c", "d", "e"]), ["e", "d", "c", "b", "a"]);
  });
  it("fill", () => {
    assert.deepStrictEqual(fill(new Array(5), "x"), ["x", "x", "x", "x", "x"]);
  });
  it("copyWithin", () => {
    assert.deepStrictEqual(copyWithin(["a", "b", "c", "d", "e"], 0, 3, 4), ["d", "b", "c", "d", "e"]);
  });
});
```

## Support Policy

### Do

- Provide immutable version of `Array.prototype` method
- Provide each method as an module
  - All prototype method: `import { push } from "@minikit/array"`
- ECMAScript compatible API

For example, `@minikit/array` method should return same result with native API.

```js
import { splice } from "@minikit/array";
var array = [1, 2, 3];
// immutable
var resultArray = splice(array, -1, 1, "x");
// native
array.splice(-1, 1, "x");
assert.deepStrictEqual(array, resultArray);
```

### Do not

- Add non-standard method in ECMAScript
  - e.g.) `update`, `delete`, `merge`...
- Each method depended on other method

## Related

- [Pure javascript immutable arrays](https://vincent.billey.me/pure-javascript-immutable-array/ "Pure javascript immutable arrays")
- [georapbox/immutable-arrays: Immutable versions of normally mutable array methods](https://github.com/georapbox/immutable-arrays "georapbox/immutable-arrays: Immutable versions of normally mutable array methods")
- [micnews/immutable-array-methods](https://github.com/micnews/immutable-array-methods "micnews/immutable-array-methods")
- [kolodny/immutability-helper: mutate a copy of data without changing the original source](https://github.com/kolodny/immutability-helper "kolodny/immutability-helper: mutate a copy of data without changing the original source")

## License

MIT © azu & billgo
npm package: @minikit/errors
Description: Rich JavaScript errors
Author: Billgo
Latest version: 0.1.1

# @minikit/errors

This module provides several classes in support of Joyent's. If you find any of the behavior here confusing or surprising, check out that document first.

- printf-style arguments for the message
- chains of causes
- properties to provide extra information about the error
- creating your own subclasses that support all of these

The classes here are:

- **ApiError**: a subclass of TError that adds a http api errno.
- **SystemError**: a subclass of TError that adds a system errno.
npm package: @minikit/parse-json
Description: @minikit/parse-json
Author: Billgo
Latest version: 0.1.0

# @minikit/parse-json

> Parse JSON with more helpful errors

## Install

```sh
npm install @minikit/parse-json
```

## Usage

```js
import parseJson, {JSONError} from '@minikit/parse-json';

const json = '{\n\t"foo": true,\n}';


JSON.parse(json);
/*
undefined:3
}
^
SyntaxError: Unexpected token }
*/


parseJson(json);
/*
JSONError: Unexpected token } in JSON at position 16 while parsing near '{      "foo": true,}'

  1 | {
  2 |   "foo": true,
> 3 | }
    | ^
*/


parseJson(json, 'foo.json');
/*
JSONError: Unexpected token } in JSON at position 16 while parsing near '{      "foo": true,}' in foo.json

  1 | {
  2 |   "foo": true,
> 3 | }
    | ^
*/


// You can also add the filename at a later point
try {
	parseJson(json);
} catch (error) {
	if (error instanceof JSONError) {
		error.fileName = 'foo.json';
	}

	throw error;
}
/*
JSONError: Unexpected token } in JSON at position 16 while parsing near '{      "foo": true,}' in foo.json

  1 | {
  2 |   "foo": true,
> 3 | }
    | ^
*/
```

## API

### parseJson(string, reviver?, filename?)

Throws a `JSONError` when there is a parsing error.

#### string

Type: `string`

#### reviver

Type: `Function`

Prescribes how the value originally produced by parsing is transformed, before being returned. See [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter
) for more.

#### filename

Type: `string`

The filename displayed in the error message.

### JSONError

Exposed for `instanceof` checking.

#### fileName

Type: `string`

The filename displayed in the error message.

#### codeFrame

Type: `string`

The printable section of the JSON which produces the error.
npm package: @minikit/pretty-ms
Description: library template
Author: Billgo
Latest version: 0.2.0

# @minikit/pretty-ms

> Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`

## Install

```sh
npm install @minikit/pretty-ms
```

## Usage

```js
import prettyMs from "@minikit/pretty-ms";

prettyMs(1337000000);
//=> '15d 11h 23m 20s'

prettyMs(1337);
//=> '1.3s'

prettyMs(133);
//=> '133ms'

// `compact` option
prettyMs(1337, { compact: true });
//=> '1s'

// `verbose` option
prettyMs(1335669000, { verbose: true });
//=> '15 days 11 hours 1 minute 9 seconds'

// `colonNotation` option
prettyMs(95500, { colonNotation: true });
//=> '1:35.5'

// `formatSubMilliseconds` option
prettyMs(100.40008, { formatSubMilliseconds: true });
//=> '100ms 400µs 80ns'

// Can be useful for time durations
prettyMs(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5));
//=> '35m'
```

## API

### prettyMs(milliseconds, options?)

#### milliseconds

Type: `number`

Milliseconds to humanize.

#### options

Type: `object`

##### secondsDecimalDigits

Type: `number`
Default: `1`

Number of digits to appear after the seconds decimal point.

##### millisecondsDecimalDigits

Type: `number`
Default: `0`

Number of digits to appear after the milliseconds decimal point.

Useful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime_time).

##### keepDecimalsOnWholeSeconds

Type: `boolean`
Default: `false`

Keep milliseconds on whole seconds: `13s` → `13.0s`.

Useful when you are showing a number of seconds spent on an operation and don't want the width of the output to change when hitting a whole number.

##### compact

Type: `boolean`
Default: `false`

Only show the first unit: `1h 10m` → `1h`.

Also ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`.

##### unitCount

Type: `number`
Default: `Infinity`

Number of units to show. Setting `compact` to `true` overrides this option.

##### verbose

Type: `boolean`
Default: `false`

Use full-length units: `5h 1m 45s` → `5 hours 1 minute 45 seconds`

##### separateMilliseconds

Type: `boolean`
Default: `false`

Show milliseconds separately. This means they won't be included in the decimal part of the seconds.

##### formatSubMilliseconds

Type: `boolean`
Default: `false`

Show microseconds and nanoseconds.

##### colonNotation

Type: `boolean`
Default: `false`

Display time using colon notation: `5h 1m 45s` → `5:01:45`. Always shows time in at least minutes: `1s` → `0:01`

Useful when you want to display time without the time units, similar to a digital watch.

Setting `colonNotation` to `true` overrides the following options to `false`:

- `compact`
- `formatSubMilliseconds`
- `separateMilliseconds`
- `verbose`

## Related

- [pretty-ms](https://github.com/sindresorhus/pretty-ms) - Convert milliseconds to a human readable string
- [pretty-bytes](https://github.com/sindresorhus/pretty-bytes) - Convert bytes to a human readable string

## Notes

Migrating from `pretty-ms` because it does not support CommonJS.
npm package: @minikit/read-pkg
Description: @minikit/read-pkg
Author: Billgo
Latest version: 0.1.0

# @minikit/read-pkg

> Read a package.json file

## Why

- [Throws more helpful JSON errors](https://github.com/sindresorhus/parse-json)
- [Normalizes the data](https://github.com/npm/normalize-package-data#what-normalization-currently-entails)

## Install

```sh
npm install @minikit/read-pkg
```

## Usage

```js
import { readPackage } from "@minikit/read-pkg";

console.log(await readPackage());
//=> {name: 'read-pkg', …}

console.log(await readPackage({ cwd: "some-other-directory" }));
//=> {name: 'unicorn', …}
```

## API

### readPackage(options?)

Returns a `Promise<object>` with the parsed JSON.

### readPackageSync(options?)

Returns the parsed JSON.

#### options

Type: `object`

##### cwd

Type: `URL | string`
Default: `process.cwd()`

Current working directory.

##### normalize

Type: `boolean`
Default: `true`

[Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.

### parsePackage(packageFile, options?)

Parses an object or string into JSON.

Note: `packageFile` is cloned using [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) to prevent modification to the input object. This function is available from Node.js 18 on. In environments without `structuredClone` (such as Node.js 16), a shallow spread is used instead, which can cause deep properties of the object to be modified. Consider cloning the object before using `parsePackage` if that's the case.

#### packageFile

Type: `object | string`

An object or a stringified object to be parsed as a package.json.

#### options

Type: `object`

##### normalize

Type: `boolean`
Default: `true`

[Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.

## Related

- [read-pkg-up](https://github.com/sindresorhus/read-pkg-up) - Read the closest package.json file
- [write-pkg](https://github.com/sindresorhus/write-pkg) - Write a `package.json` file
- [load-json-file](https://github.com/sindresorhus/load-json-file) - Read and parse a JSON file
npm package: @minikit/terror
Description: Types of Errors in Node.js
Author: Billgo
Latest version: 0.1.2

# @minikit/terror

Handling errors properly means not only reducing the development time by finding bugs and errors easily but also developing a robust codebase for large-scale applications.

正确处理错误不仅意味着通过轻松查找错误和错误来减少开发时间，而且还意味着为大规模应用程序开发强大的代码库。

## Types of Errors in Node.js

First of all, it is necessary to have a clear understanding of errors in Node.js. In general, Node.js errors are divided into two distinct categories.

- **Operational errors** represent runtime problems whose results are expected and should be dealt with in a proper way. Operational errors don’t mean the application itself has bugs, but developers need to handle them thoughtfully. It means they need to be handled properly. Here’s a list of common operational errors:

  - Failed to connect to a database server.
  - Invalid inputs by the user.
  - Request timeout.
  - Resource not found (server responds with a 404 response code).

- **Programmer errors** represent unexpected bugs in poorly written code. They mean the code itself has some issues to solve and was coded wrong. A good example is to try to read a property of “undefined.” To fix the issue, the code has to be changed. That is a bug a developer made, not an operational error.
  - Trying to read a property on an object that is not defined.
  - Invoking or calling an asynchronous function without a callback.
  - Passing a string where a number was expected.
npm package: @minilibs/env-parser
Description: A simple parser to convert environment variables to object 🛠️
Author: @bfzli
Latest version: 0.0.4

# **Env Parser 🛠️**

Parse your variables into objects easily, or use it to build something greater with them. Below is a simple explanation of how to use it. It runs smoothly on both the client and the server without conflicts.

When you provide `envPath` (the path to your .env file) as a prop, the function is called on the server side. Alternatively, if you provide `envContent` (a copy-paste of your env files), it runs on either the client or the backend, depending on your environment.

<br />

## **How To Env Parser**

### **Importing the Env Parser**

```ts
import EnvParser from '@minilibs/env-parser'

// or

import { EnvParser } from '@minilibs/env-parser'
```

### **Using The Import**

```ts
// If you want to run it on the server side, provide envPath. For client-side usage, provide envContent, as files cannot be read directly from the client.

const { success, error variables } = await EnvParser({
    envContent: '...',
    envPath: '.env'
})


if (success) {
    // Prints the parsed variables; may be empty if none are found.
    console.log({ variables })
}

else {
    // If an error occurs, it will provide details to help diagnose the issue.
    console.error({ error })
}

```

### Fixing a Known Issue with Next.js

If you are running Next.js on the server and encountering a 'module not found' error after you installed `@minilibs/env-parser`, you can resolve this by adding the following code to your next.config.js file:

```
const nextConfig = {
    webpack: (config, { isServer }) => {
        if (!isServer) {
            config.resolve.fallback = {
                fs: false,
                net: false,
                tls: false,
                request: false,
                readline: false,
                stream: false,
            }
        }

        return config
    }
}

module.exports = nextConfig
```