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

objix

v1.16.2

Published

A dangerously convienient, high performance and super lightweight utility (2.7kb) that injects methods into the Object prototype to sugar for many common use cases working with Javascript objects.

Downloads

40

Readme

Objix

Objix is a delightfully convienient, high performance, zero dependency and super lightweight utility which extends the javascript standard library to sugar many common use cases for working with any objects.

The functions are all non enumerable and include copies of Object class methods and Array prototype methods applied to the values of the object as well others to delete keys, stringify, promisify, memoize, compare, split/join objects, check types, log messages and trapping/observing property assignments.

This library is highly optimised with zero copy operations where possible. The source is only 3.5kb (2.7kb minified) which allows for fast loading and easy integration without additional compilation or tree shaking. There is however limited type checking to guard against unwanted side effects, and there may be some undiscovered edge case that do not behave as expected. Performance in most cases is significantly faster than lodash equivalents especially when working with small objects. For example ob.map(fn) is typically over 65% faster than _.mapValues(ob, fn) and some operations such as pick can be several thousand times quicker according to simple benchmarks.

Interactive docs and demos are availble on https://objix.dev/#/docs/api.

Getting Started - Node

  • Install:

    > npm i -save objix
  • Require:

    require('objix')
    var o = { a: 1 }.map(v => v + 1).log()

Getting Started - Browser

<script src="https://cdn.jsdelivr.net/gh/mattaylor/objix@main/objix.min.js"></script>

<script>
  var o = { a: 1 }.map(v => v + 1).log()
</script>

Prototype Methods

The following methods are availble to all Objects via protoype inheritence, unless overwritten by a subclass.

| | | | -------------------------------------- | ------------------------------------------------------------------------------------------- | | map | Return a copy of this with all entries mapped by a function | | flatMap | FlatMap a function to all entries of an this | | values | Return values of this | | create | Create a new Object based on this as a prototoype | | keys | Return keys of this | | entries | Return [key,value] entry pairs of this | | is | Check type of this | | has | Check if this includes some value | | [@@iterator] | Iterate through values of this | | clean | Return a copy of this without falsey entries | | pick | Create a copy of this with only entries with specific keys or values that that match a filter function | | find | Find keys of this which match a function or value | | assign | Assign new properties to this | | extend | Assign default properties to this | | same | Return new object like this with properties shared with another | | diff | Return new object like this with properties not shared with another | | delete | Remove keys from this | | some | Test a function against at least one entry of this | | every | Test a function against all entries of this | | at | Lookup value by key path | | $ | Coerce this into a string with configurable formatting | | clone | Clone this with configurable depths | | join | Join objects together with this with array property values | | split | Split this into multiple objects from array property values | | contains | Check if this contains all entries from another object to a given depth. | | eq | Compare key and value identity between this and other objects to a given depth | | size | Return number of entres in this. | | keyBy | Re-index values of this this using a given key path | | memo | Memoize this as a function with configurable result cache expiration | | bind | Assign a function as a method of this with optional memoization | | log | Conditionally write this to the console with an optional message | | try | Call a function against this and catch any exceptions | | trap | Create a proxy around this to intercept property assignments | | new | Create a new object from another using this as a prototype, including traps | | wait | Create a Promise which resolves this after a timeout or as determined by another function |

Fluent Method Chaining

Most of these function return objects including those modifying this and so can be fluently chained together.

var o = { a: 0, b: 1, c: 2 }
  .filter(v => v > 0)
  .log('POSITIVE') // 2022-10-07T00:00 POSITIVE { b: 1, c: 2 }
  .map(v => v + 1)
  .log('INCREMENT') // 2022-10-07T00:00 INCREMENT { b: 2, c: 3 }

Function Aliases

All functions documented below are also callable with a '_' prefix to the function name. This can help ensure that the function is callable when overwritten by other object property assignments.

var o = { a: 1 }.size() == { a: 1 }._size() //true
var o = { a: 1 }.find(v => v) == { a: 1 }._find(v => v) //true

Simple Classes

Any object can act as a class from which new objects can be derived. All properties of this are inherited - including traps!!

var Person = { firstName: 'john', lastName: 'doe' }
  .trap(v => new Date(v).getDate(), 'Invalid date', 'dob')
  .bind('age', t => Math.floor((Date.now() - new Date(t.dob)) / 31536000000))
  .bind('name', t => t.firstName + ' ' + t.lastName)

var p1 = Person.new({ firstName: 'jane' })
p1.name() // 'jane doe'
p1.try(
  p => (p.dob = 'foobar'),
  e => e.log()
) // Uncaught 'Invalid date [dob, foobar]'
p1.dob = '10/10/2000'
p1.age() // 22

Module Exports

All functions listed below are also available using traditional module exports, where the first argument of the function will be the object that the function is targeting as this if called via the object O.p.

const _ = require('objix')

_.size({ a: 1 }) == { a: 1 }.size() // true
_.find({ a: 1 }, v => v) == { a: 1 }.find(v => v) //true