New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@kogs/utils

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kogs/utils - npm Package Compare versions

Comparing version
1.2.7
to
1.3.7
+7
-0
index.d.ts

@@ -8,2 +8,8 @@ /// <reference types="node" />

/**
* Generates a new error class with the given name.
* @param name - Name of the error class.
* @returns A new error class with the given name.
*/
export declare function errorClass(name: string): new () => Error;
/**
* Recursively scans the given directory and returns an array of file paths.

@@ -49,2 +55,3 @@ * @param dir - Directory to be scanned.

collectFiles: typeof collectFiles;
errorClass: typeof errorClass;
arrayToStream: typeof arrayToStream;

@@ -51,0 +58,0 @@ streamToArray: typeof streamToArray;

@@ -5,2 +5,20 @@ import stream from 'node:stream';

/**
* Generates a new error class with the given name.
* @param name - Name of the error class.
* @returns A new error class with the given name.
*/
export function errorClass(name) {
return class extends Error {
/**
* Creates a new error instance with the given message and options.
* @param message - Error message.
* @param options - Additional options.
*/
constructor(message, options) {
super(message, options);
this.name = name;
}
};
}
/**
* Recursively scans the given directory and returns an array of file paths.

@@ -108,2 +126,3 @@ * @param dir - Directory to be scanned.

collectFiles,
errorClass,
arrayToStream,

@@ -110,0 +129,0 @@ streamToArray,

+1
-1
{
"name": "@kogs/utils",
"version": "1.2.7",
"version": "1.3.7",
"type": "module",

@@ -5,0 +5,0 @@ "description": "A collection of standalone utility functions.",

# @kogs/utils
![tests status](https://github.com/Kruithne/kogs-utils/actions/workflows/github-actions-test.yml/badge.svg) [![license badge](https://img.shields.io/github/license/Kruithne/kogs-utils?color=blue)](LICENSE)
`@kogs/util` is a [Node.js](https://nodejs.org/en/) package that provides a collection of utility functions.
`@kogs/utils` is a [Node.js](https://nodejs.org/en/) package that provides a collection of utility functions.

@@ -57,2 +57,30 @@ - Provides ["pure functions"](https://en.wikipedia.org/wiki/Pure_function).

### errorClass
`errorClass(name: string): new() => Error`
This method accepts a name and returns a new error class that can be used to create new errors.
```js
const MyCustomError = errorClass('MyCustomError');
throw new MyCustomError('Something went wrong!');
// error.name === 'MyCustomError'
// error.message === 'Something went wrong!'
```
The purpose of this factory is to reduce the amount of boilerplate required to create custom errors.
```js
// Common boilerplate:
class MyCustomError extends Error {
constructor(message) {
super(message);
this.name = 'MyCustomError';
}
}
// Equivalent to:
const MyCustomError = errorClass('MyCustomError');
```
### arrayToStream

@@ -59,0 +87,0 @@ `arrayToStream(input: Array<ReadableChunk>, objectMode: boolean = true): stream.Readable`