diff --git a/.github/ISSUE_TEMPLATE/1_bug_report.md b/.github/ISSUE_TEMPLATE/1_bug_report.md index 3fb6a58..111dbb9 100644 --- a/.github/ISSUE_TEMPLATE/1_bug_report.md +++ b/.github/ISSUE_TEMPLATE/1_bug_report.md @@ -2,7 +2,7 @@ name: Bug report about: Create a bug report to help improve SvCoreLib title: "[Bug] " -labels: "\U0001F41B bug" +labels: "bug" assignees: Sv443 --- diff --git a/.github/ISSUE_TEMPLATE/2_feature_request.md b/.github/ISSUE_TEMPLATE/2_feature_request.md index d61355f..f151ecc 100644 --- a/.github/ISSUE_TEMPLATE/2_feature_request.md +++ b/.github/ISSUE_TEMPLATE/2_feature_request.md @@ -2,7 +2,7 @@ name: Feature request about: Suggest a feature or an idea for SvCoreLib title: "[Feature] " -labels: "✨ enhancement" +labels: "enhancement" assignees: Sv443 --- diff --git a/.github/ISSUE_TEMPLATE/3_change_request.md b/.github/ISSUE_TEMPLATE/3_change_request.md index 34f8ebe..6e0933c 100644 --- a/.github/ISSUE_TEMPLATE/3_change_request.md +++ b/.github/ISSUE_TEMPLATE/3_change_request.md @@ -2,7 +2,7 @@ name: Change request about: Suggest changes to an already existing feature title: "[Change] " -labels: "✨ enhancement" +labels: "enhancement" assignees: Sv443 --- diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index f64e9ee..4aabf88 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -4,8 +4,8 @@ contact_links: - name: "Documentation" about: "Please read the documentation before opening a new issue" - url: "https://github.com/Sv443-Network/SvCoreLib/wiki" + url: "https://github.com/Sv443-Network/SvCoreLib/blob/master/docs.md#readme" - - name: "Chat" + name: "Discord" about: "If you want to chat with the Sv443 Network community or need help, you can join the Discord server" url: "https://dc.sv443.net" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b26d20..bd116af 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,9 @@ jobs: env: CI: "true" - name: Install ESLint # installs ESLint - idk why it doesn't pull this out of the devDependencies but whatever - run: npm i -g eslint + run: | + npm i -g eslint + npm i -D eslint env: CI: "true" - name: Run ESLint # Runs ESLint on the project @@ -52,4 +54,3 @@ jobs: with: args: '🚫 **SvCoreLib CI** (triggered by `{{GITHUB_ACTOR}}` on `{{GITHUB_REF}}`) has failed (see https://github.com/Sv443-Network/SvCoreLib/commit/{{GITHUB_SHA}}/checks)' if: failure() - diff --git a/.github/workflows/publish.disabled b/.github/workflows/publish.yml.disabled similarity index 100% rename from .github/workflows/publish.disabled rename to .github/workflows/publish.yml.disabled diff --git a/.gitignore b/.gitignore index 546d7fb..7c93aa3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,44 +2,12 @@ logs *.log npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov # nyc test coverage .nyc_output -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories +# Dependency directory node_modules/ -jspm_packages/ # TypeScript v1 declaration files typings/ @@ -53,12 +21,6 @@ typings/ # Optional eslint cache .eslintcache -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - # Optional REPL history .node_repl_history @@ -70,40 +32,7 @@ typings/ # dotenv environment variables file .env -.env.test - -# parcel-bundler cache (https://parceljs.org/) -.cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and *not* Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - - +# dev test files test.js -test.ts \ No newline at end of file +test.ts diff --git a/.npmignore b/.npmignore index 0cc9e5b..51f38da 100644 --- a/.npmignore +++ b/.npmignore @@ -9,3 +9,4 @@ package-npm.json .editorconfig test.js test.ts +docs.md diff --git a/.snyk b/.snyk new file mode 100644 index 0000000..7ee4a75 --- /dev/null +++ b/.snyk @@ -0,0 +1,4 @@ +# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. +version: v1.19.0 +ignore: {} +patch: {} diff --git a/.vscode/settings.json b/.vscode/settings.json index ef6b7bc..851aabe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,20 +1,30 @@ { // requires extension "coenraads.bracket-pair-colorizer-2" "bracket-pair-colorizer-2.colors": [ - "#4B8AE3", + "#0f6a8f", "#659061", - "#41BCA3", - "#EDD553", - "#E09563", - "#B85442" + "#41bca3", + "#edd553", + "#e09563", + "#b85442", + "#8ced68", + "#7d56a6", ], // requires extension "fabiospampinato.vscode-highlight" + "highlight.regexFlags": "g", "highlight.regexes": { - "((jsl\\.|scl\\.)?unused\\([a-zA-Z_,\\[\\]\\s\"'$]+\\);*)": [ // jsl.unused([some_var, some_other_var]); or scl.unused("foo"); or just unused(variable) + "((scl\\.)?unused\\([a-zA-Z_,\\[\\]\\s\\-\":.]*\\)\\s*;?)": [ // scl.unused(xy); or just unused(xy); { - "backgroundColor": "rgba(0, 0, 0, 0.2)", - "color": "#f88" + "backgroundColor": "inherit", + "color": "rgba(221, 102, 102, 0.75)" + } + ], + "(TODO:?)": [ // TODO: or TODO but not todo + { + "backgroundColor": "#cd5", + "color": "#000", + "overviewRulerColor": "#cd5" } ], "(#MARKER)": [ // #MARKER test @@ -25,19 +35,31 @@ "overviewRulerColor": "#f41" } ], - "(#SECTION ([^\\S\\r\\n]*\\w+)*[:]*)": [ // #SECTION test + "(#SECTION ([^\\S\\r\\n]*[\\w,.\\-_&]+)*[:]*)": [ // #SECTION test, 123 & foo { "backgroundColor": "#44f", "color": "white", "overviewRulerColor": "#44f" } ], - "(#DEBUG#?)": [ // #DEBUG# or just #DEBUG + "(#DEBUG#?)": [ // #DEBUG# or #DEBUG { "backgroundColor": "#ff0", "color": "blue", "overviewRulerColor": "#ff0" } - ] + ], + "(IMPORTANT:)": [ // IMPORTANT: + { + "backgroundColor": "#a22", + "color": "#fff" + } + ], + "(FIXME:)": // FIXME: + { + "backgroundColor": "#a22", + "color": "#fff", + "overviewRulerColor": "#752020" + } }, } \ No newline at end of file diff --git a/SvCoreLib.d.ts b/SvCoreLib.d.ts index 7eada3f..3024729 100644 --- a/SvCoreLib.d.ts +++ b/SvCoreLib.d.ts @@ -19,48 +19,42 @@ import { Connection, QueryOptions } from "mysql"; * Describes an object that is JSON-compatible, aka doesn't contain self- / circular references or non-primitive JS properties * [Source](https://github.com/microsoft/TypeScript/issues/1897#issuecomment-338650717) */ -declare type JSONCompatible = boolean | number | string | null | JSONArray | JSONMap; +export type JSONCompatible = boolean | number | string | null | JSONArray | JSONMap; interface JSONMap { [key: string]: JSONCompatible; } interface JSONArray extends Array {} /** * Describes a value that has a `.toString()` method, meaning it can be converted to a string */ -declare interface Stringifiable { +export interface Stringifiable { toString(): string; } -/** - * Base class for all of SCL's error classes - */ -declare class SCLError extends Error -{ - date: Date; -} - -declare type PromiseState = "initialized" | "pending" | "fulfilled" | "rejected"; - /** * ![icon](https://sv443.net/resources/images/svcorelib_tiny.png) + * * ## SvCoreLib - * The core library used in almost all of Sv443's projects. + * #### The core library used in almost all projects of the [Sv443 Network](https://sv443.net/) and [Sv443](https://github.com/Sv443) * * --- * - * **[Documentation](https://github.com/Sv443-Network/SvCoreLib/blob/master/docs.md#readme) • [GitHub Repo](https://github.com/Sv443-Network/SvCoreLib) • [Discord](https://dc.sv443.net)** - * - * [Changelog](https://github.com/Sv443-Network/SvCoreLib/blob/master/changelog.md#readme) - * + * **[Documentation](https://github.com/Sv443-Network/SvCoreLib/blob/master/docs.md#readme) • [Changelog](https://github.com/Sv443-Network/SvCoreLib/blob/master/changelog.md#readme) • [GitHub Repo](https://github.com/Sv443-Network/SvCoreLib) • [Discord](https://dc.sv443.net)** + * * --- * + * If you like this library please consider [supporting me ❤](https://github.com/sponsors/Sv443) + * + * * @author Sv443 * @license [MIT](https://sv443.net/LICENSE) - * @version 1.14.0 + * @version 1.14.2 * @module svcorelib */ declare module "svcorelib" { //#MARKER functions + + //#SECTION Miscellaneous /** @@ -139,7 +133,7 @@ declare module "svcorelib" { * @returns Better readable array as string * @since 1.7.0 */ - function readableArray(array: Stringifiable[], separators?: string, lastSeparator?: string): string; + function readableArray(array: (string | Stringifiable)[], separators?: string, lastSeparator?: string): string; /** * 🔹 Transforms the `value` parameter from the numerical range [`range_1_min`-`range_1_max`] to the numerical range [`range_2_min`-`range_2_max`] 🔹 @@ -157,11 +151,11 @@ declare module "svcorelib" { /** * 🔹 Use this if you are using a linter that complains about unused vars. * As this function basically does nothing, you can even leave it in once the variable is used again and nothing will break. 🔹 - * @param any Any amount of variable(s) of any type + * @param variables Any amount of variable(s) of any type * @since 1.8.0 * @version 1.9.0 Function now accepts an infinite number of parameters */ - function unused(...any: T[]): void; + function unused(...variables: any): void; /** * 🔹 Replaces a character from the specified `string` at the specified `index` with the value of `replacement` 🔹 @@ -245,7 +239,7 @@ declare module "svcorelib" { * @throws Throws a "TypeError" if the parameter `str` is not a string or if one of the values could not be converted to a string * @since 1.12.0 */ - function insertValues(str: string, ...values: Stringifiable[]): string; + function insertValues(str: string, ...values: (string | Stringifiable)[]): string; /** * 🔸 Offers a few functions to generate seeded random numbers. @@ -253,7 +247,8 @@ declare module "svcorelib" { */ namespace seededRNG { /** - * Represents a seed to be used in functions of the `seededRNG` namespace + * Represents a seed to be used in functions of the `seededRNG` namespace. + * Note that seeds can't start with the number `0` as they need to be compatible with both `string` and `number` types */ type Seed = (number | string); @@ -336,7 +331,7 @@ declare module "svcorelib" { * @param possibleValues An array containing all characters that can be injected into the final UUID * @since 1.14.0 */ - function custom(uuidFormat: string, possibleValues: Stringifiable[]): string; + function custom(uuidFormat: string, possibleValues: (string | Stringifiable)[]): string; /** * 🔹 Creates a decimal [0-9] UUID with a given format. This uses a RNG that is even more random than the standard Math.random() 🔹 @@ -487,7 +482,7 @@ declare module "svcorelib" { * @since 1.8.0 * @version 1.9.2 Added the option of using the Promise API instead of a callback */ - function downloadFile(url: string, destPath?: string, options?: DownloadOptions): Promise; + function downloadFile(url: string, destPath?: string, options?: DownloadOptions): Promise; //#SECTION file system @@ -632,11 +627,14 @@ declare module "svcorelib" { /** * 🔹 Checks if the process is currently running in the debugger environment. - * This can be useful because some features like child processes and reading from stdin do not work in certain debuggers. - * Should support all major debuggers. 🔹 + * This can be useful because some features like child processes and reading from stdin do not work in certain debuggers. 🔹 + * ❗ This function should support all major debuggers but this isn't guaranteed! + * If it doesn't detect your debugger, pass the command line argument `--debug` or `--inspect` ❗ + * @param {string} [checkArg] If provided, checks if this command line argument is present. Makes the function return `true` if it is. * @returns true, if the process is currently running in a debugger, false if not. * @since 1.9.0 * @version 1.13.0 Moved namespace + * @version 1.14.2 Added `inspector.url()` check for better results */ function inDebugger(): boolean; @@ -652,6 +650,10 @@ declare module "svcorelib" { //#MARKER classes + + + //#SECTION ProgressBar + /** * 🔹 Creates a dynamic progress bar in the CLI 🔹 * @@ -661,6 +663,11 @@ declare module "svcorelib" { * ![ProgressBar example image](https://sv443.net/cdn/jsl/doc/progress_bar_small.png) */ class ProgressBar { + /** The character to use for filled parts of the progress bar */ + public filledChar: string; + /** The character to use for blank / empty parts of the progress bar */ + public blankChar: string; + /** * 🔹 Creates a dynamic progress bar with a percentage and custom message display 🔹 * @@ -703,6 +710,8 @@ declare module "svcorelib" { getRemainingIncrements(): number; } + //#SECTION MenuPrompt + /** An option of a menu of the menu prompt */ interface MenuPromptMenuOption { @@ -792,6 +801,9 @@ declare module "svcorelib" { * ![MenuPrompt example image](https://sv443.net/cdn/jsl/doc/menu_prompt_small.png) */ class MenuPrompt { + /** This is where all texts of the MenuPrompt are stored. Use this to translate or change them. */ + public localization: MenuPromptLocalization; + /** * 🔹 Creates an interactive prompt with one or many menus - add them using `MenuPrompt.addMenu()`. * To translate the messages, you can use the `MenuPrompt.localization` object, which is where all localization variables are stored. 🔹 @@ -838,7 +850,7 @@ declare module "svcorelib" { currentMenu(): number; /** - * 🔹 Returns the current results of the menu prompt. + * 🔹 Returns the current results of the menu prompt. * This does **not** close the menu prompt, unlike `close()` 🔹 * @returns Returns the results of the menu prompt or null, if there aren't any results yet * @since 1.8.0 @@ -854,7 +866,7 @@ declare module "svcorelib" { validateMenu(menu: MenuPromptMenu): boolean | string[]; } - //#MARKER FolderDaemon + //#SECTION FolderDaemon /** The options of the FolderDaemon */ interface FolderDaemonOptions @@ -920,7 +932,7 @@ declare module "svcorelib" { intervalCall(): void; } - //#MARKER SelectionMenu + //#SECTION SelectionMenu /** * An object of settings to be used in the constructor of the `SelectionMenu` class @@ -970,6 +982,11 @@ declare module "svcorelib" { * **Make sure to use the keyword `new` to create an object of this class, don't just use it like this!** */ class SelectionMenu { + /** + * Used to translate the SelectionMenu + */ + public locale: SelectionMenuLocale; + /** * 🔹 Constructs a new object of class SelectionMenu. * The SelectionMenu is an interactive menu in the Command Line Interface with a list of options that can be scrolled through and selected. 🔹 @@ -1018,13 +1035,12 @@ declare module "svcorelib" { * @since 1.11.0 */ close(): string | boolean; - - /** - * Used to translate the SelectionMenu - */ - public locale: SelectionMenuLocale; } + //#SECTION StatePromise + + type PromiseState = "initialized" | "pending" | "fulfilled" | "rejected"; + /** * 🔹 This class is a wrapper for the Promise API. * It keeps track of the state of the promise it wraps. 🔹 @@ -1072,6 +1088,16 @@ declare module "svcorelib" { * 🔸 Contains all of SCL's custom error classes 🔸 */ namespace Errors { + /** + * 🔹 Base class for all of SCL's error classes. + * Adds a `date` property that tracks the exact time an Error instance was created. 🔹 + */ + class SCLError extends Error + { + /** A Date instance set to the exact time this Error instance was created */ + date: Date; + } + /** * 🔹 This error gets thrown if an invalid path was provided 🔹 * @since 1.12.0 @@ -1111,6 +1137,10 @@ declare module "svcorelib" { //#MARKER objects + + + //#SECTION info + /** * 🔹 Info about SvCoreLib 🔹 * @since 1.5.0 @@ -1136,6 +1166,8 @@ declare module "svcorelib" { let documentation: string; } + //#SECTION colors + /** * 🔹 Use this to add color to your console output 🔹 * @since 1.8.0 diff --git a/changelog.md b/changelog.md index 12d0cb2..0ad4c2d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,54 +1,66 @@ ## SvCoreLib - Changelog -### Latest version: [1.14.1](#1141) +### Latest version: [1.14.2](#1142) -

-
Version History - Click to expand +
+ +
Click to expand version history
-**JSLib-npm** - -- 1.6.0 - - [1.6.5](#165) - - [1.6.6](#166) -- [1.7.0](#170) -- [1.8.0](#180) - - [1.8.1](#181) - - [1.8.2](#182) - - [1.8.3](#183) - - [1.8.4](#184) -- [1.9.0](#190) - - [1.9.1](#191) - - [1.9.2](#192) - - [1.9.3](#193) - - [1.9.4](#194) - -**SvCoreLib** - -- [1.10.0](#1100) -- [1.11.0](#1110) - - [1.11.1](#1111) -- [1.12.0](#1120) -- [1.13.0](#1130) - - [1.13.1](#1131) -- [1.14.0](#1140) - - [1.14.1](#1141) +> **JSLib-npm** +> +> - 1.6.x +> - [1.6.5](#165) +> - [1.6.6](#166) +> - [1.7.0](#170) +> - [1.8.0](#180) +> - [1.8.1](#181) +> - [1.8.2](#182) +> - [1.8.3](#183) +> - [1.8.4](#184) +> - [1.9.0](#190) +> - [1.9.1](#191) +> - [1.9.2](#192) +> - [1.9.3](#193) +> - [1.9.4](#194) +> +> **SvCoreLib** +> +> - [1.10.0](#1100) +> - [1.11.0](#1110) +> - [1.11.1](#1111) +> - [1.12.0](#1120) +> - [1.13.0](#1130) +> - [1.13.1](#1131) +> - [1.14.0](#1140) +> - [1.14.1](#1141) +> - [1.14.2](#1142) +> +>
-
+

---- +## 1.14.2 -

+- Fixes + - Fixed `.d.ts` type declarations ([issue #27](https://github.com/Sv443-Network/SvCoreLib/issues/27)) + - Fixed `system.inDebugger()` not detecting debugger ([issue #30](https://github.com/Sv443-Network/SvCoreLib/issues/30)) + - Set `mysql` as a peer dependency ([issue #29](https://github.com/Sv443-Network/SvCoreLib/issues/29)) + - Improved documentation a little bit +- Internal stuff + - Added CodeQL analysis workflow + +
## 1.14.1 - Fixes - `filesystem.exists()` can now actually be used 🤦 ([issue #25](https://github.com/Sv443-Network/SvCoreLib/issues/25)) -

+
## 1.14.0 @@ -63,14 +75,14 @@ - Security - Audited dependencies -

+
## 1.13.1 - Security: - Fixed vulnerability in package `netmask` ([CVE-2021-28918](https://sick.codes/sick-2021-011)) -

+
## 1.13.0 ### Migration warnings: @@ -98,7 +110,7 @@ - Package `mysql` isn't included in the dependencies ([issue #21](https://github.com/Sv443/SvCoreLib/issues/21)) - Definition of `system.softShutdown()`'s callback function was wrong ([issue #20](https://github.com/Sv443/SvCoreLib/issues/20)) -

+
## 1.12.0 - Added functions @@ -111,19 +123,19 @@ - Added SCL's custom error classes to new namespace `scl.Errors` - Massively improved the documentation -

+
## 1.11.1 - My dumbass left some debug text in -

+
## 1.11.0 ### The SelectionMenu update - Added the class `SelectionMenu` to create a menu with a scrollable list of options a user can select - Added the function `allOfType()` to see if all items of an array are of a specified type -

+
## 1.10.0 ### The initial release diff --git a/docs.md b/docs.md index 72a92a2..be1fad0 100644 --- a/docs.md +++ b/docs.md @@ -23,7 +23,7 @@ You can join the Sv443 Network Discord server if you need help or just want to c
-### To get started, please go to [the installation section.](#installation) +### >> To get started, please go to [the installation section.](#installation) << Otherwise, see the table of contents just below.

@@ -91,12 +91,13 @@ Otherwise, see the table of contents just below. - [SelectionMenu](#SelectionMenu) - a menu that can be scrolled through - [StatePromise](#StatePromise) - wrapper around the Promise API that provides a way to check its state - **[Errors](#errors)** + - [SCLError](#errorssclerror) - base class of all SCL error classes - [InvalidPathError](#errorsinvalidpatherror) - an invalid path was provided - [NotAFolderError](#errorsnotafoldererror) - the provided path is not a folder - [PatternInvalidError](#errorspatterninvaliderror) - GLOB pattern is invalid - [NoStdinError](#errorsnostdinerror) - terminal doesn't have a stdin channel - [InvalidMimeTypeError](#errorsinvalidmimetypeerror) - MIME type is not valid - - [SqlConnectionNotEstablishedError](#sqlconnectionnotestablishederror) - SQL connection is invalid + - [SqlConnectionNotEstablishedError](#errorssqlconnectionnotestablishederror) - SQL connection is invalid - **[Objects](#objects)** - [colors](#colors) - color text in the console - [info](#info) - information about SCL @@ -105,9 +106,12 @@ Otherwise, see the table of contents just below. - [Disclaimer](#disclaimer) - [Privacy Policy](#privacy-policy) - [Security Policy](#security-policy) - - [Site Notice / Impressum](#site-notice) -




+
+ +--- + +



# Installation @@ -117,7 +121,7 @@ npm i svcorelib ``` Troubleshooting: Make sure your workspace contains a `package.json` file. If not, use `npm init` to initialize your workspace with npm. -




+


# Usage @@ -157,7 +161,7 @@ If you only want to import a select number of features and don't like always hav -




+


@@ -173,7 +177,7 @@ If you only want to import a select number of features and don't like always hav - All code examples don't require installing any third party packages (excluding SCL's dependencies which should get auto-installed). - The example GIF included in some features uses the exact code that is included in that same feature under "example code". - Custom objects (aka interfaces) are declared at the bottom of the class they are part of or at the bottom of the same section if they belong to a normal function. -- Class constructors start with the header `Constructor` and don't have a return type (since they return an instance of themselves). +- Class constructors start with the header `Constructor` and don't have a return type (since they return an instance of the class they belong to). - This instance, created with the `new` keyword, should then be used to call the methods that are part of that same class. - Do not use methods on the class directly unless the documentation explicitly states that they are static methods! @@ -188,26 +192,26 @@ SCL uses a TypeScript type declaration file (`.d.ts`) in order to provide docume ![(Image)](https://cdn.sv443.net/scl/docs/jsdoc_ide.gif)
- ----
- Each piece of documentation will have a description. It is delimited from other sections by this emoji: 🔹 - If you are looking at a namespace, for example [`scl.filesystem`](#file-system), its description will be marked with this emoji: 🔸 - Some of the functions / methods have special quirks to look out for or will be deprecated. This warning section is delimited from other sections with this emoji: ❗ -- Deprecated features should be unlisted in your IDE but if not or you explicitly entered their name, they are indicated with a `@deprecated` tag and they will contain this emoji: ❌. Their descriptions should also tell you if there are alternatives. +- Deprecated features should be unlisted in your IDE but if not or you explicitly entered their name, they are indicated with a `@deprecated` tag and they will contain this emoji: ❌ + Their descriptions should also tell you if there are alternatives. - You will always encounter a `@since` tag, which indicates with which version the feature was introduced. - The `@version` tag will tell you that something changed in a certain version. -- If a function / method can throw an error, the `@throws` tag will tell you when this might happen and of which class the Error might be. -- Private class methods should be unlisted but if not, they will start with an underscore, will be tagged with `@private` and their description will be delimited from other sections with this emoji: ❌. Private methods shouldn't be used, or else something might break. +- If a function / method can throw an error, the `@throws` tag will tell you when this might happen and of which class the Error instance might be. +- Private class methods should be unlisted but if not, they will start with an underscore, will be tagged with `@private` and their description will be delimited from other sections with this emoji: ❌ + Private methods shouldn't be used, or else something might break.




# Functions This section tells you all about the static functions SCL offers. -You have to call these *without* creating a class instance using the `new` keyword. +You have to call these *without* creating a class instance (without using the `new` keyword).
@@ -283,9 +287,9 @@ This namespace, accessed with `scl.filesystem`, contains a few file-related func > ### filesystem.readdirRecursiveSync() -> Basically the same thing as [filesystem.readdirRecursive()](#filesystemreaddirrecursive), but this function blocks code execution, thus making it synchronous. +> Basically the same thing as [filesystem.readdirRecursive()](#filesystemreaddirrecursive), but this function blocks code execution until it's finished, making it synchronous. > -> ❗ This function blocks the main thread, contrary to the asynchronous [filesystem.readdirRecursive()](#filesystemreaddirrecursive) so it is recommended that you try to use the async function over this synchronous one. +> ❗ This function uses blocking operations, contrary to the asynchronous [filesystem.readdirRecursive()](#filesystemreaddirrecursive) so it is recommended that you try to use the async function over this synchronous one. > ```ts > scl.filesystem.readdirRecursiveSync(folder: string): string[] > ``` @@ -618,18 +622,21 @@ This namespace, accessed with `scl.http`, offers functions that make using Node' > ### http.getClientEncoding() -> This function parses the `Accept-Encoding` header of a clien't request and returns the most efficient and modern encoding methods the client supports. -> Currently supported encoding methods (sorted by priority, highest priority first) are: -> - `br` ([Brotli](https://en.wikipedia.org/wiki/Brotli)) -> - `gzip` ([Gzip / Lempel-Ziv / LZ77](https://en.wikipedia.org/wiki/Gzip)) -> - `deflate` ([Deflate](https://en.wikipedia.org/wiki/DEFLATE)) -> - `compress` ([Lempel-Ziv-Welch / LZW](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch)) -> - `identity` (No Encoding / Raw Data) -> +> This function parses the `Accept-Encoding` header of a clien't request and returns the most efficient and modern encoding methods the client supports. > If no header was provided or the client doesn't support any encodings, `"identity"` is returned, meaning the client wants the original, non-encoded data. +> > ```ts > scl.http.getClientEncoding(req: http.IncomingMessage): string > ``` +> +> Currently supported encoding methods (sorted by priority, highest priority first) are: +> | Encoding | Name | Priority | +> | :-- | :-- | :-: | +> | `br` | [Brotli](https://en.wikipedia.org/wiki/Brotli) | 4 | +> | `gzip` | [Gzip / Lempel-Ziv / LZ77](https://en.wikipedia.org/wiki/Gzip) | 3 | +> | `deflate` | [Deflate](https://en.wikipedia.org/wiki/DEFLATE) | 2 | +> | `compress` | [Lempel-Ziv-Welch / LZW](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch) | 1 | +> | `identity` | No Encoding / Raw Data | 0 | > >
Example Code - click to show > @@ -640,15 +647,19 @@ This namespace, accessed with `scl.http`, offers functions that make using Node' > http.createServer((req, res) => { > if(req.method == "GET") > { -> let clientEncoding = scl.http.getClientEncoding(req); +> console.log(`Client accepts encodings: ${req.headers["accept-encoding"]}`); // "Client accepts encodings: gzip, deflate" +> +> // let SCL determine the encoding that's highest on the priority list and also supported by the client (present in the "Accept-Encoding" header) +> const clientEncoding = scl.http.getClientEncoding(req); > -> console.log(clientEncoding); // "gzip" +> res.writeHead(200, { "Content-Type": "text/plain; utf-8" }); +> res.end(`Selected encoding: ${clientEncoding}`); // "Selected encoding: gzip" > } -> }).listen(80, Andi BeAndi B. Roller-Anditt, err => { +> }).listen(80, undefined, err => { > if(err) > console.error(`Error while setting up HTTP server: ${err}`); > else -> console.log(`HTTP server listening at 127.0.0.1:80`); +> console.log(`HTTP server is listening at http://127.0.0.1/`); > }); > ``` > @@ -707,7 +718,7 @@ This namespace, accessed with `scl.http`, offers functions that make using Node' > The parameter `res` contains the server's response to the client's request. > Put the string you want to send to the client in the parameter `text`. > The parameter `mimeType` needs to be passed a valid [MIME (Multipurpose Internet Mail Extensions) type.](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) If left empty, this will default to `text/plain`. -> The `statusCode` parameter needs to be passed a [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) number. If left empty, this will default to `200`. +> The `statusCode` parameter needs to be passed a [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) number. If left empty, this will default to `200` > > The function will return `Angola Angola Mutti` if everything went according to plan or will return a string containing an error message if not. > ```ts @@ -980,15 +991,18 @@ This namespace, accessed with `scl.system`, offers functions that refer to the s > ### system.inDebugger() -> Checks if the process is currently running in the debugger environment. +> Checks if the process is currently running in a debugger. > This can be useful because some features like child processes and reading from stdin do not work in most debuggers. -> Should support all major Node.js debuggers. -> Returns `true` if the current process runs in a debugger environment - else returns `false` +> Should support all major Node.js debuggers, but this is not guaranteed. +> Returns `true` if the current process runs in a debugger - else returns `false` +> +> If `checkArg` is provided, the function searches for a matching command line argument and returns `true` if it was found. +> This enables you to explicitly set the debugger state, for example if your debugger isn't properly detected by this function. > ```ts -> scl.system.inDebugger(): boolean +> scl.system.inDebugger(checkArg?: string): boolean > ``` > ->
Example Code - click to show +>
Basic example code - click to show > > ```js > const { system, MenuPrompt } = require("svcorelib"); @@ -996,12 +1010,28 @@ This namespace, accessed with `scl.system`, offers functions that refer to the s > if(!system.inDebugger()) > { > // SCL's MenuPrompt doesn't work in some debuggers since it needs to read from process.stdin -> let mp = new MenuPrompt(); +> const mp = new MenuPrompt(); > // ... > } > ``` > >
+> +>
Example with custom CLI argument - click to show +> +> ```js +> const { system } = require("svcorelib"); +> +> console.log(process.argv); // [ '.../node.exe', '.../this_file.js', '--debugger-enabled' ] +> +> // explicitly test if `--debugger-enabled` is present in the CLI arguments +> if(system.inDebugger("--debugger-enabled")) +> { +> console.log("in debugger"); +> } +> ``` +> +>



@@ -1011,7 +1041,7 @@ This namespace, accessed with `scl.system`, offers functions that refer to the s > Prevents the process from being shut down. > This can prevent people from exiting the process using CTRL+C. > Using `process.exit()` in your script will still exit the process though! -> If you want the process to be able to be shut down again, use [`scl.yesShutdown()`](#yesshutdown). +> If you want the process to be able to be shut down again, use [`scl.yesShutdown()`](#systemyesshutdown). > > Note: this only listens for the signals "SIGINT" and "SIGTERM". > Due to many OSes not supporting it, using "SIGKILL" will still kill the process. @@ -1024,7 +1054,7 @@ This namespace, accessed with `scl.system`, offers functions that refer to the s > ### system.yesShutdown() -> Removes the script shut down prevention that was previously enabled with [`scl.noShutdown()`](#noshutdown). +> Removes the script shut down prevention that was previously enabled with [`scl.noShutdown()`](#systemnoshutdown). > ```ts > scl.system.yesShutdown(): void > ``` @@ -2351,10 +2381,55 @@ Constructing multiple objects of these classes will not make them interfere with This class namespace, accessed with `scl.Errors`, contains all of SCL's custom error classes. They are used by SCL but feel free to also use these. The classes have to be constructed with the `new` keyword. -Also, all of these classes inherit from [JavaScript's `Error` class.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) + +All of these classes extend from the [base class `SCLError`](#errorssclerror), which in turn extends from the [`Error` class.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) +The `SCLError` base class adds a property `date`, which is an instance of `Date` and which represents the exact time the error instance was created.

+ + +> ### Errors.SCLError +> This is the base class of all of SCL's Error classes. +> +> +>

+> +> +> > ### Constructor +> > Constructs a new object of the class `SCLError` +> > +> > The param `message` is optional. It contains a more detailed error message. +> > ```ts +> > new Errors.SCLError(message?: string) +> > ``` +> +> +>


+> +> +> > **
Example Code - Click to view** +> > +> > ```js +> > const { Errors, colors } = require("svcorelib"); +> > +> > try +> > { +> > throw new SCLError("idk, something probably went wrong"); +> > } +> > catch(err) +> > { +> > // SCLError exposes the `date` property, which you can use for logging, debugging, etc.: +> > console.error(`${colors.fg.red}Error thrown at ${err.date.toString()}: ${colors.rst}${err.toString()}`); +> > } +> > ``` +> > +> >
+ + +


+ + > ### Errors.InvalidPathError > This error gets thrown when a provided path is invalid or doesn't exist on the current device. @@ -2668,14 +2743,10 @@ Please create a backup before using this library if you want to be extra secure ## Security Policy [Click here to view the security policy.](./.github/SECURITY.md) -
- -## Site Notice -[Click here to view the site notice / Impressum.](https://sv443.net/imprint/en) -



+
Made with ❤️ by [Sv443](https://github.com/Sv443) diff --git a/package-lock.json b/package-lock.json index 904e4f7..a158163 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,25 +1,27 @@ { - "name": "@sv443-network/svcorelib", - "version": "1.14.1", + "name": "svcorelib", + "version": "1.14.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "@sv443-network/svcorelib", - "version": "1.14.0", + "name": "svcorelib", + "version": "1.14.2", "license": "MIT", "dependencies": { "deep-diff": "^1.0.2", "fs-extra": "^9.0.1", "keypress": "^0.2.1", - "minimatch": "^3.0.4", - "mysql": "^2.18.1" + "minimatch": "^3.0.4" }, "devDependencies": { "@types/mysql": "^2.15.17", "@types/node": "^14.6.0", "eslint": "^7.22.0", "snyk": "^1.592.0" + }, + "peerDependencies": { + "mysql": "^2.18.1" } }, "node_modules/@arcanis/slice-ansi": { @@ -1294,6 +1296,7 @@ "version": "9.0.0", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==", + "peer": true, "engines": { "node": "*" } @@ -2686,9 +2689,9 @@ } }, "node_modules/glob-parent": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", - "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, "dependencies": { "is-glob": "^4.0.1" @@ -3932,6 +3935,7 @@ "version": "2.18.1", "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz", "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", + "peer": true, "dependencies": { "bignumber.js": "9.0.0", "readable-stream": "2.3.7", @@ -3946,6 +3950,7 @@ "version": "2.3.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "peer": true, "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -3959,12 +3964,14 @@ "node_modules/mysql/node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "peer": true }, "node_modules/mysql/node_modules/string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "peer": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -4021,9 +4028,9 @@ } }, "node_modules/normalize-url": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", - "integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==", + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz", + "integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==", "dev": true, "engines": { "node": ">=8" @@ -5210,7 +5217,7 @@ "snyk-try-require": "1.3.1", "source-map-support": "^0.5.11", "strip-ansi": "^5.2.0", - "tar": "^6.1.0", + "tar": "^6.1.6", "tempfile": "^2.0.0", "update-notifier": "^5.1.0", "uuid": "^3.3.2", @@ -6073,6 +6080,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=", + "peer": true, "engines": { "node": ">= 0.6" } @@ -6321,9 +6329,9 @@ } }, "node_modules/tar": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", - "integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", + "version": "6.1.6", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.6.tgz", + "integrity": "sha512-oaWyu5dQbHaYcyZCTfyPpC+VmI62/OM2RTUYavTk1MDr1cwW5Boi3baeYQKiZbY2uSQJGr+iMOzb/JFxLrft+g==", "dev": true, "dependencies": { "chownr": "^2.0.0", @@ -7967,7 +7975,8 @@ "bignumber.js": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", - "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==", + "peer": true }, "binjumper": { "version": "0.1.4", @@ -9058,9 +9067,9 @@ } }, "glob-parent": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", - "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, "requires": { "is-glob": "^4.0.1" @@ -10076,6 +10085,7 @@ "version": "2.18.1", "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz", "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", + "peer": true, "requires": { "bignumber.js": "9.0.0", "readable-stream": "2.3.7", @@ -10087,6 +10097,7 @@ "version": "2.3.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "peer": true, "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -10100,12 +10111,14 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "peer": true }, "string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "peer": true, "requires": { "safe-buffer": "~5.1.0" } @@ -10157,9 +10170,9 @@ } }, "normalize-url": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", - "integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==", + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz", + "integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==", "dev": true }, "npm-run-path": { @@ -11056,7 +11069,7 @@ "snyk-try-require": "1.3.1", "source-map-support": "^0.5.11", "strip-ansi": "^5.2.0", - "tar": "^6.1.0", + "tar": "^6.1.6", "tempfile": "^2.0.0", "update-notifier": "^5.1.0", "uuid": "^3.3.2", @@ -11801,7 +11814,8 @@ "sqlstring": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", - "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=" + "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=", + "peer": true }, "ssh2": { "version": "0.8.9", @@ -12007,9 +12021,9 @@ } }, "tar": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", - "integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", + "version": "6.1.6", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.6.tgz", + "integrity": "sha512-oaWyu5dQbHaYcyZCTfyPpC+VmI62/OM2RTUYavTk1MDr1cwW5Boi3baeYQKiZbY2uSQJGr+iMOzb/JFxLrft+g==", "dev": true, "requires": { "chownr": "^2.0.0", diff --git a/package.json b/package.json index 375e345..54cded9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svcorelib", - "version": "1.14.1", + "version": "1.14.2", "description": "Core Library used in almost all of my (Sv443's) projects. Feel free to use it if you want to, it contains some very nice features.", "main": "SvCoreLib.js", "scripts": { @@ -52,7 +52,9 @@ "deep-diff": "^1.0.2", "fs-extra": "^9.0.1", "keypress": "^0.2.1", - "minimatch": "^3.0.4", + "minimatch": "^3.0.4" + }, + "peerDependencies": { "mysql": "^2.18.1" }, "devDependencies": { diff --git a/src/classes/Errors.js b/src/classes/Errors.js index 01f6dea..078c365 100644 --- a/src/classes/Errors.js +++ b/src/classes/Errors.js @@ -89,6 +89,7 @@ class SqlConnectionNotEstablishedError extends SCLError { module.exports = { + SCLError, InvalidPathError, NotAFolderError, PatternInvalidError, diff --git a/src/functions/allOfType.js b/src/functions/allOfType.js index e9f8eb9..e0fe765 100644 --- a/src/functions/allOfType.js +++ b/src/functions/allOfType.js @@ -8,7 +8,7 @@ function allOfType(array, type) if(!possibleTypes.includes(type)) throw new TypeError(`Parameter "type" needs to be a string that contains a primitive JavaScript variable type`); - return array.every(val => typeof val == type); + return array.every(val => (typeof val === type)); } module.exports = allOfType; diff --git a/src/functions/system/inDebugger.js b/src/functions/system/inDebugger.js index 0ce66e0..2722b29 100644 --- a/src/functions/system/inDebugger.js +++ b/src/functions/system/inDebugger.js @@ -1,6 +1,23 @@ -function inDebugger() +const { url } = require("inspector"); +const unused = require("../unused"); + +function inDebugger(checkArg) { - return (typeof v8debug === "object" || /--debug|--inspect/.test(process.execArgv.join(" "))); + try + { + if(typeof checkArg === "string" && checkArg.length > 0) + return process.argv.join(" ").includes(checkArg); + } + catch(err) + { + unused(err); + } + + return ( + typeof v8debug === "object" + || /--debug|--inspect/.test(process.execArgv.join(" ")) + || typeof url() === "string" + ); } module.exports = inDebugger; diff --git a/src/functions/unused.js b/src/functions/unused.js index 650e4ff..b78580f 100644 --- a/src/functions/unused.js +++ b/src/functions/unused.js @@ -1,6 +1,6 @@ function unused(...any) { - void(any); + void any; return; }