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

js-expansion

v1.1.11

Published

Expansion of Javascript

Downloads

71

Readme

js-expansion

Javascript Expansion

NPM JavaScript Style Guide

Package to expand default Javascript types like, Array, Number and String

Install

npm install --save js-expansion

Usage

require('js-expansion')

/* Nested Array */
const collection = [
    {
        id: 1,
        name: 'Piet'
    },
    {
        id: 2,
        name: 'henry',
        friends: [
            {
                id: 3,
                name: 'Karel',
            }   
        ]
    },
]

// Get first element from Array
const firstElement = collection.first()

// Get last element from Array
const lastElement = collection.last()

// Search objects in array on key => value
const foundElement = collection.findBy('name', 'henry')

// Search object index in array on key => value
const indexElement = collection.findIndexBy('name', 'henry')

// Get value from array by dot notation: Karel
const friend_name = collection.get('1.friends.0.name')

// Sort array by object key (direction desc)
const sortedCollection = collection.sortBy('id', 'desc')

// default direction asc
const sortedCollection = collection.sortBy('id') 

// Delete element from array
const deleteCollection = collection.delete(2)

// Delete element from array with objects
const deleteCollection = collection.delete(2, 'id')

// Add new element to the Array if the value is already present in the collection is does not adds it again.
const addCollection = collection.save(1)

// Add new element to the Array with objects
const addCollection = collection.save({
    id: 3,
    name: 'klaas'
})

// Update existing element in the array (default updates on key `id`)
const updateCollection = collection.save({
    id: 1,
    name: 'klaas'
})

// Update existing element in the array by custom key
const updateCollection = collection.save({
    name: 'klaas',
    age: 10
}, 'name')


/* Normal Array methods */
const array = ['piet', 'henry']

// Search Array
const searchResult = array.search('piet')

// Clone Array
const clonedArray = array.clone()

/* String methods */
const string = 'piet'

// Capitalize string
const capitalized = string.ucfirst()

/* Number methods */ 
const seconds = 60

// Convert seconds to time: 00:00
seconds.time()

const price = 10.50

// Convert number/float price into label: € 10,50
price.price('EUR', 'nl-NL')

Helpers

require('js-expansion')
const {query, form, request} = require('js-expansion')

// Convert object to FormData (for multipart/form-data)
const formData = form({
    title: 'henry',
    thumbnail: File,
    permissions: [1, 2, 3]
})


// Create GET params url from object: ?search=piet&paginate=10
const queryUrl = query({search: 'piet', paginate: 10})

// Create request from params: /users/1?details=true
// replaces variables from url with params, and adds (only when type is 'get') the remaining params to the query url using the query method.
// available types: ('get', 'post', 'put', 'delete')
const requestUrl = request('get', '/users/{id}', {id: 1, details: true})

Tests

cd example
yarn install
yarn start

License

MIT © tychovbh