Git Product home page Git Product logo

svcorelib's Introduction

logo

SvCoreLib

MIT License GitHub issues Vulnerabilities


Core Library used in the projects of Sv443 and the Sv443 Network,
containing tons of miscellaneous quality of life features

Contains builtin TypeScript definitions



Most notable features:

  • Interactive CLI tools like a menu and a progress bar
  • Networking tools like downloading files and pinging URLs or efficiently serving data to a connecting client
  • File system tools like reading a directory recursively, downloading a file or supervising a directory for changes
  • Randomization tools like generating UUIDs or a seeded RNG
  • Misc tools involving array manipulation

See a list of all features here.


Install:

Use this command in a terminal window inside your Node.js project:

npm i svcorelib

If you don't intend on using SQL functions, use npm i svcorelib --no-optional


Contributors:

Thank you very much to these contributors for improving SvCoreLib ❤️

Name Contributions
canarado Added TypeScript declarations, fixed grammar
ThatCopy Fixed documentation, tested the code

Dependencies:

I made SvCoreLib so it needs as few dependencies as possible, but in order to ensure quality and stability, these dependencies are needed:

* = optional, see installation




Made with ❤️ by Sv443 and others
Like SvCoreLib? Please consider supporting our development

svcorelib's People

Contributors

canarado avatar dependabot[bot] avatar sv443 avatar thatcopy avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

svcorelib's Issues

[Bug] SelectionMenu is incompatible with libraries such as 'prompts'

Using the below example code demonstrates how SCL makes the prompts library capture keyboard input twice, after a SelectionMenu was opened at some point

const prompt = require("prompts"); // https://www.npmjs.com/package/prompts
const { SelectionMenu } = require("svcorelib");

const sm = new SelectionMenu("Example");

sm.setOptions([ "Foo", "Bar" ]);

sm.onSubmit(async () => {
    const { res } = await prompt({
        type: "text",
        name: "res",
        message: "Enter something:",
    });

    console.log(res);
});

sm.open();

I believe not even using sm.close() helped.

[Feature] `scl.weightedRandom()` for randomness based on predefined weights

Something like

const items = [ "foo", "bar" ];
const weights = [ 1, 2 ];

const result = scl.weightedRandom(items, weights);

would return a random entry of the items array, but the RNG should be modified, so that "bar" is 200% likely to occur, while "foo" is only at 100%, so "bar" is twice as likely to be returned as "foo".



Optional feature:

Add an overload to this new function that needs to be passed an iterator function to resolve each array items' weights; this is kinda how the Array.map() and Array.reduce() methods work:

const items = [ "foo", "bar", "baz" ];

function iterator(current, last, all)
{
	// return the char code of the first letter of the string
	// letters further down the alphabet have a higher weight (a = 1, z = 26)
	const weight = (current.charCodeAt(0) - 96);

	// Default to weight 1 if somehow the calculations above can produce NaN
	if(isNaN(weight))
		return 1;

	return weight;
}

const result = scl.weightedRandom(items, iterator);

The iterator function gets called on each item and it should return a number that's not NaN (check with isNaN()). Everything that is returned will be accumulated into the weights array of the previous example and based on this a random item is selected and returned.

Migrate to TypeScript

  1. Find a bundler that does CJS, ESM and TS
  2. Do the migration thingy (yuck)
  3. Cry
  4. PAin
  5. suffering
  6. done :)

[Feature] takeRandomItem()

Like randomItem() but mutates the array to remove that item
Alternatively add this as a param to randomItem()

SCL should make use of peer dependencies

Currently mysql is declared as a dependency, meaning it must be installed (even if it is not needed), adding quite a lot of sub-dependency clutter.
Solution is to declare it as a peer dependency and doing some Node magic to throw an error if a peer function is used without its dependency.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.