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

@bopepsi/lotide

v1.0.2

Published

A mini clone of the [Lodash](https://lodash.com) library.

Downloads

5

Readme

Lotide

A mini clone of the Lodash library.

Purpose

BEWARE: This library was published for learning purposes. It is not intended for use in production-grade software.

This project was created and published by me as part of my learnings at Lighthouse Labs.

Usage

Install it:

npm install @bopepsi/lotide

Require it:

const _ = require('@bopepsi/lotide');

Call it:

const results = _.tail([1, 2, 3]) // => [2, 3]

Documentation

The following functions are currently implemented:

const assertArraysEqual = function (actual, expected) {
    let ans = true;
    const helper = (arr1, arr2) => {
        if (arr1.length !== arr2.length) ans = false;
        for (var i = 0; i < arr1.length; i++) {
            if (Array.isArray(arr1[i])) helper(arr1[i], arr2[i]);
            else { if (arr1[i] !== arr2[i]) ans = false; }
        };
    }
    helper(actual, expected);
    if (ans) {
        console.log(`✅✅✅ Assertion Passed: ${actual} === ${expected}`);
        return true;
    }
    if (!ans) {
        console.log(`🔴🔴🔴 Assertion Failed: ${actual} !== ${expected}`);
        return false;
    }
};

const assertEqual = function (actual, expected) {
    if (actual === expected) console.log(`✅✅✅ Assertion Passed: ${actual} === ${expected}`);
    else console.log(`🔴🔴🔴 Assertion Failed: ${actual} !== ${expected}`);
    return actual === expected;
};


const assertObjectsEqual = (actual, expected) => {
    const inspect = require('util').inspect;
    if (Object.keys(actual).length !== Object.keys(expected).length) {
        console.log(`🔴🔴🔴 Assertion Failed: ${inspect(actual)} !== ${inspect(expected)}`);
        return false;
    }
    for (var key in actual) {
        let expectedVal = expected[key];
        if (Array.isArray(actual[key])) {
            console.log('checking array')
            if (actual[key].length !== expectedVal.length) {
                console.log(`🔴🔴🔴 Assertion Failed: ${inspect(actual)} !== ${inspect(expected)}`);
                return false;
            }
            for (var i = 0; i < actual[key].length; i++) {
                if (actual[key][i] !== expectedVal[i]) {
                    console.log(`🔴🔴🔴 Assertion Failed: ${inspect(actual)} !== ${inspect(expected)}`);
                    return false;
                }
            }
            continue;
        }
        if (typeof actual[key] !== 'object') {
            console.log('checking primitive vals')
            if (actual[key] !== expectedVal) {
                console.log(`🔴🔴🔴 Assertion Failed: ${inspect(actual)} !== ${inspect(expected)}`);
                return false;
            }
        } else {
            console.log('checking obj')
            return assertObjectsEqual(actual[key], expectedVal);
        }
    } console.log(`✅✅✅ Assertion Passed: ${inspect(actual)} === ${inspect(expected)}`);

    return true;
};

const countLetters = str => {
    let ans = {};
    for (var char of str.replace(' ', '')) {
        ans[char] = (ans[char] || 0) + 1;
    }
    return ans;
};

const countOnly = function (allItems, itemsToCount) {
    let temp = {};
    for (var item of allItems) {
        if (itemsToCount[item]) temp[item] = (temp[item] || 0) + 1;
    };
    return temp;
};

const eqArrays = function (actual, expected) {
    let ans = true;
    const helper = (arr1, arr2) => {
        if (arr1.length !== arr2.length) ans = false;
        for (var i = 0; i < arr1.length; i++) {
            if (Array.isArray(arr1[i])) helper(arr1[i], arr2[i]);
            else { if (arr1[i] !== arr2[i]) ans = false; }
        };
    }
    helper(actual, expected);
    return ans;
};

const eqObjects = (obj1, obj2) => {
    if (Object.keys(obj1).length !== Object.keys(obj2).length) return false;
    for (var key in obj1) {
        let obj2Val = obj2[key];
        if (Array.isArray(obj1[key])) {
            console.log('checking array')
            if (obj1[key].length !== obj2Val.length) return false;
            for (var i = 0; i < obj1[key].length; i++) {
                if (obj1[key][i] !== obj2Val[i]) return false;
            }
            continue;
        }
        if (typeof obj1[key] !== 'object') {
            console.log('checking primitive vals')
            if (obj1[key] !== obj2Val) return false;
        } else {
            console.log('checking obj')
            return eqObjects(obj1[key], obj2Val);
        }
    }
    return true;
};

const findKey = (obj, match) => {
    for (var key in obj)
        if (match(obj[key])) return key;
};

const findKeyByValue = (obj, str) => {
    for (let key in obj) {
        if(obj[key]===str) return key;
    }
    return;
};

const flatten = arr => {
    let ans = [];
    for (var item of arr) {
        if (item.length) ans = ans.concat(flatten(item));
        else ans.push(item);
    }
    return ans;
};

const head = arr => arr ? arr[0] : undefined;

const letterPositions = (sentence = sentence.replace(' ', '')) => {
    const results = {};
    for (var i = 0; i < sentence.length; i++) {
        if (results[sentence[i]]) results[sentence[i]].push(i);
        else results[sentence[i]] = [i];
    }
    return results;
};

const map = (arr, transform) => {
    const results = [];
    arr.forEach(item => results.push(transform(item)));
    return results;
};

const middle = array => {
    if (array.length < 2) return [];
    if (array.length % 2 !== 0) return array.slice(array.length / 2, array.length / 2 + 1);
    else return array.slice(Math.floor(array.length / 2-1), Math.ceil(array.length / 2+1));
};

const tail = arr => {
    if (arr.length === 1) return [];
    let result = [...arr].slice(1);
    arr.slice()
    return result;
};

const takeUntil = function (array, callback) {
    let results = [];
    for (var element of array) {
        if (!callback(element)) results.push(element);
        if(callback(element)) break;
    }
    return results;
};

const without = (words, filter) => {
    let length = words.length;
    for (var i = 0; i < length; i++) {
        if (filter.includes(words[i])) {
            words.splice(i, 1);
            i--;
            length = words.length;
        }
    }
};