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

@hamanpreet/lotide

v1.0.1

Published

JavaScript code offering a wide range of functions for manipulating arrays, objects, strings, and other data types.

Downloads

6

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 @hamanpreet/lotide

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

  1. head: Takes an array as its argument and returns the first element of the array.

head([1, 2, 3]); //returns 1 for [1, 2, 3]

assertArraysEqual: Takes two arrays as arguments and checks whether they are equal or not. If the two arrays are equal, the function returns true, otherwise it returns false.

assertArraysEqual([0, 1, 3], [0, 1, 3]); // returns true

  1. assertEqual: Takes two values as arguments and checks whether they are equal or not. If the two values are equal, the function returns true, otherwise it returns false.

assertEqual("Lighthouse","Lighthouse"); //returns true

  1. assertObjectsEqual: Takes two objects as arguments and checks whether they are equal or not. If the two objects are equal, the function returns true, otherwise it returns false.

const multiColorShirtObject = { colors: ["red", "blue","green"], size: "medium" }; const anotherMultiColorShirtObject = { size: "medium", colors: ["red", "blue","green"] }; assertObjectsEqual(multiColorShirtObject,anotherMultiColorShirtObject); // returns true

  1. countLetters: Takes a string as its argument and returns an object with a count of each letter in the string.

countLetters("lighthouse in the house"); results["o"] === 2 // returns true

  1. countOnly: Takes an array of strings and an object of items to count as its arguments, and returns an object with a count of each item in the array that is specified in the object.

const names = ["John", "Jane", "John", "Mary", "John"]; const counts = countOnly(names, { John: true, Jane: false, Mary: true }); console.log(counts); //returns { John: 3, Mary: 1 }

  1. eqArrays: Takes two arrays as its arguments and returns a boolean value indicating whether the two arrays are equal or not.

eqArrays([1, 3, 4], [4, 3, 1]) // returns false

  1. eqObjects: Takes two objects as its arguments and returns a boolean value indicating whether the two objects are equal or not.

const shirtObject = { size: "medium", color: "red" }; const anotherShirtObject = { size: "medium", color: "red" }; eqObjects(shirtObject , anotherShirtObject); //returns true

  1. findKeyByValue: Takes an object and a value as its arguments, and returns the first key in the object that has the specified value. If no key is found with the specified value, the function returns undefined.

const bestTVShowsByGenre = { sciFi: "The Expanse", comedy: "Brooklyn Nine-Nine", drama: "The Wire" }; findKeyByValue(bestTVShowsByGenre, "The Wire"); //returns drama

  1. flatten: Takes an array as its argument and returns a new array with all nested arrays flattened into a single level array.

const arr = [1,2,[3, 4],5,[6]]; flatten(arr); //returns [1,2,3,4,5,6]

  1. letterPositions: Takes a string as its argument and returns an object with the indices of each letter in the string.

const results = letterPositions("hello world"); assertArraysEqual(results.h === [0]) //returns true

  1. map: Higher-order function in JavaScript that creates a new array by applying a given function to each element of an existing array.

const words = ["ground", "control", "to", "major", "tom"]; const results2 = map(words, word => word[0]); // returns ['g', 'c', 't', 'm', 't']

  1. middle: Takes an array as its argument and returns the middle element(s) of the array. If the array has an even number of elements, the function returns an array with the two middle elements. If the array has an odd number of elements, the function returns an array with the single middle element.

middle([1, 2, 3]); //returns [2]

  1. tail: Takes an array as its argument and returns a new array containing all elements of the original array except for the first element. If the original array has only one element or is empty, the function returns an empty array.

tail([1, 2, 3]) //returns [2,3]

  1. takeUntil: Takes two arguments: an array and a callback function. The function returns a new array that contains all the elements from the original array up to (but not including) the first element that causes the callback function to return a truthy value.

const data2 = ["I've", "been", "to", "Hollywood", ",", "I've", "been", "to", "Redwood"]; const results2 = takeUntil(data2, x => x === ','); assertArraysEqual(results2,[ "I've", 'been', 'to', 'Hollywood' ]);

  1. without: Takes two arrays as its arguments: an array to modify and an array of elements to remove from the first array. The function returns a new array with all the elements of the first array except for the elements specified in the second array.

const myInput = [1,2,3,4,5]; const itemsToRemove = [3,5]; without(myInput,itemsToRemove) // returns [1,2,4]