Giter Club home page Giter Club logo

svcorelib's People

Contributors

canarado avatar dependabot[bot] avatar sv443 avatar thatcopy avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

svcorelib's Issues

[Feature] takeRandomItem()

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

[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 :)

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.

[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.

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.