npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@magicyan/core

v1.0.19

Published

Very simple functions for you to use in your code

Downloads

898

Readme

Magicyan Core

Install with

npm install @magicyan/core

This lib provides simple and practical functions to use

Check

import { equalsIgnoreCase, includesIgnoreCase } from "@magicyan/core";

console.log(equalsIgnoreCase("Hello World", "hello world")); // true
console.log(includesIgnoreCase("Javascript Program", "program")); // true

Convert

import { equalsIgnoreCase, includesIgnoreCase } from "@magicyan/core";

console.log(hexToRgb("#3a8cc3")); // 3837123
console.log(rgbToHex(3837123)); // #3a8cc3

Format

import { toNull, notFound, brBuilder, spaceBuilder, replaceText, captalize, limitText } from "@magicyan/core";

console.log(toNull()); // null
asyncMethod().catch(toNull); // ignore error

// value: number | null
const amount = notFound(value); // number | undefined

const text = brBuilder("Hello world", "This is javascript!");
console.log(text) ;
// Hello world
// This is javascript

const adm = "Rincko";
const action = "promoted";
const text = spaceBuilder("Administrator", adm, "has been", action);
console.log(text); // Administrator Rincko has been promoted

// lang.json
{
    "welcome": {
        "en-US": "Hi var(name), welcome to var(libname) lib",
        "pt-BR": "Olá var(name), seja bem vindo à lib var(libname)"
    }
}
// command.ts
import { replaceText } from "@magicyan/discord";
import lang from "./lang"
// ...

const locale = "en-US";

const text = replaceText(lang.welcome[locale], {
    "var(name)": user.displayName // "Rincko Dev",
    "var(libname)": lib.getName() // "@magicyan/core"
})

console.log(text) // Hi Rincko Dev, welcome to @magicyan/core lib

const captalizedWord = captalize("hello world");
console.log(capitalizedWord); // Output: "Hello world"

const captalizedText = captalize("i love brazil", true);
console.log(capitalizedText); // Output: "I Love Brazil"

const bigText = "Introduction to magicyan/core lib! A lib with many useful functions";
const limitedText = limitText(bigText, 21, "...");
console.log(limitedText) // Introduction to magic...

Math

import { random, parseIntOr, parseFloatOr } from "@magicyan/core";

console.log(random.int(0, 10)) // 7
console.log(random.int(0, 10)) // 8
console.log(random.int(0, 10)) // 10

console.log(random.float(0, 10)) // 7.157077577891795
console.log(random.float(0, 10)) // 1.0842981808087804
console.log(random.float(0, 10)) // 6.304121080765393

console.log(parseIntOr("nan", 2)) // 2;
console.log(parseFloatOr("nan", -8)) // 08;
console.log(parseIntOr("29.09", 10)) // 29;
console.log(parseFloatOr("0.3", 18)) // 0.3;

Promises

import { sleep, createInterval } from "@magicyan/core";

await sleep(2000) // ==> wait 2 seconds

let count = 0
const timer = createInterval({
    time: 1000,
    run(stop){
        console.log(count)
        if (count >= 10){
            console.log("end")
            stop()
            return
        }
        count++
    }
}) // 0, 1, 3, 4 ...

if (otherCondition) timer.stop();

Utils

import { copyObject, mergeObject, toMergeObject } from "@magicyan/core";

const originalUser = { name: "Jhondoe" };
const userCopy = copyObject(originalUser);
originalUser.name = "Victor";
console.log(originalUser.name) // Victor
console.log(userCopy.name) // Jhondoe

const administrator = toMergeObject(userCopy, { perms: [1, 2] })
console.log(JSON.stringify(userCopy)) // {"name":"Jhondoe"}
console.log(JSON.stringify(administrator)) // {"name":"Jhondoe","perms":[1,2]}

mergeObject(administrator, { sector: "A" });
console.log(JSON.stringify(administrator)) // {"name":"Jhondoe","perms":[1,2],"sector":"A"}

Validation

import { isEmail, isUrl } from "@magicyan/core";

console.log(isEmail("[email protected]")) // true
console.log(isEmail("jhondoeemail.com")) // false
console.log(isEmail("[email protected]")) // true
console.log(isEmail("@gmail.com")) // false

console.log(isUrl("localhost:3000")) // false
console.log(isUrl("https://npmjs.com")) // true
console.log(isUrl("http://github.com")) // true
console.log(isUrl("github.com")) // false