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

struct-class

v1.0.0

Published

Struct class from Ruby to JavaScript

Downloads

9

Readme

struct-class Build Status

:construction: Struct class from Ruby to JavaScript

Struct acts like a normal custom user-created class, but provides some nice default functionality and shortcuts when you don't need a full-fledged class.

Install

NPM

$ npm install struct-class --save

Yarn

$ yarn add struct-class

Usage

import Struct from 'struct-class'

class Account extends Struct.new('owner', 'balance') {}

const account = new Account('Helton', 12345.67)

console.log(account) 
// => #<struct Struct::Account owner=Helton, balance=12345.67>

API

All the methods below (but the Struct.new, which is static) are instance methods or attributes/properties.

Struct.new (...parameters)

Return Type: class

Returns a class with a default constructor using all the parameters provided.

dig (...keys)

Return Type: any

Extracts the nested value specified by the sequence of key objects by calling dig at each step, returning undefined if any intermediate step is undefined.

each (fn)

Return Type: void

Iterates over the struct members, returning their property names.

eachPair (fn)

Return Type: void

Iterates over the struct members, returning their property names and values

inspect ()

Return Type: string

Describes the contents of the struct in a string.

length

Attribute Return Type: number

Returns the number of struct members.

members

Attribute Return Type: Array[string]

Returns the struct members as an array of string.

select (fn)

Return Type: void

Iterates over the struct members, returning their property names.

size

Attribute Return Type: number

Returns the number of struct members.

toString ()

Return Type: string

Describes the contents of the struct in a string.

toArray ()

Return Type: Array[any]

Returns the values for this struct as an Array.

toMap ()

Return Type: Map[string => any]

Returns the values for this struct as a Map.

values

Attribute Return Type: Array[any]

Returns the values for this struct as an Array.

valuesAt (....selectors)

Return Type: Array[any]

Returns the struct member values for each selector as an Array. A selector should be a number or a string representing the property name.

License

MIT © Helton Carlos de Souza