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

@rijudev/parseus

v0.0.12

Published

<h1 align="center">Parseus</h1>

Downloads

267

Readme

Parseus is a javascript library written in Typescript which allow marshall/unmarshall JSON into class instance. This library is able to run in NodeJS, Typescript or any JS platform. API Docs

Usage Javascript (ESNEXT)

class Person {
  @Field({ type: 'string', name: 'person_name' })
  name

  @Field({ readOnly: true, name: 'person_age', type: 'number' })
  age

  @Field({ name: 'person_last_name', type: 'string' })
  lastName

  @Field({ name: 'person_gender', default: 'M', type: 'string' })
  gender

  @Field({ name: 'person_created_at', type: 'date' })
  createdAt
}

const data = {
  person_name: 'Jhon',
  person_last_name: 'Smith',
  person_age: 25,
  person_created_at: '2018-01-01T12:00:00.000Z'
}
/**
 *  Returns an instance of Person like
 * {
 *   name:'Jhon',
 *   lastName: 'Smith',
 *   age: 25,
 *   gender: 'M',
 *   createdAt: Mon Jan 01 2018 08:00:00 GMT-0400 (Atlantic Standard Time) {}
 * }
 **/

const person = Parseus.decode(data).to(Person)
person.gender = 'F'
person.age = 18
person.name = 'Sara'

/**
 * The second parameter is optional, but if
 * the class instance has been mutated
 * we should pass the original class for references
 *
 * Returns an object with the next structure { [key:string]: any }
 * {
 *   "person_name": "Sara",
 *   "person_last_name": "Smith",
 *   "person_age": 18,
 *   "person_gender": F,
 *   "person_created_at": "2018-01-01T12:00:00.000Z"
 * }
 **/
const personMarshalled = Parseus.encode(person, Person)

Usage Typescript

class Person {
  @Field({ type: 'string', name: 'person_name' })
  name?: string

  @Field({ readOnly: true, name: 'person_age' })
  age?: number

  @Field({ name: 'person_last_name' })
  lastName?: string

  @Field({ name: 'person_gender', default: 'M' })
  gender?: string

  @Field({ name: 'person_created_at', type: 'date' })
  createdAt?: Date
}

const data = {
  person_name: 'Jhon',
  person_last_name: 'Smith',
  person_age: 25,
  person_created_at: '2018-01-01T12:00:00.000Z'
}
/**
 *  Returns an instance of Person like
 * {
 *   name:'Jhon',
 *   lastName: 'Smith',
 *   age: 25,
 *   gender: 'M',
 *   createdAt: Mon Jan 01 2018 08:00:00 GMT-0400 (Atlantic Standard Time) {}
 * }
 **/

const person = Parseus.decode(data).to(Person)
person.gender = 'F'
person.age = 18
person.name = 'Sara'

/**
 * The second parameter is optional, but if
 * the class instance has been mutated
 * we should pass the original class for references
 *
 * Returns an object with the next structure { [key:string]: any }
 * {
 *   "person_name": "Sara",
 *   "person_last_name": "Smith",
 *   "person_age": 18,
 *   "person_gender": F,
 *   "person_created_at": "2018-01-01T12:00:00.000Z"
 * }
 **/
const personMarshalled = Parseus.encode(person, Person)
  1. Install the npm package:

    npm install parseus --save or using yarn yarn add @rijudev/parseus

  2. You need to install reflect-metadata shim:

    npm install reflect-metadata --save or using yarn yarn add reflect-metadata

    and import it somewhere in the global place of your app:

    import 'reflect-metadata'

| Property | Description | Type | Default | | ----------- | ---------------------------------------------------------------------------------------------------------------------- | ------------ | -------- | | type | Field type. Must be one of the values from the FieldType | string | 'string' | | name | Key name in source object. if this value is not provided it takes the model field's name wrapped | string | - | | isVirtual | Indicates if field's value is ignored when marshall Object | boolean | false | | default | Indicates the initial field's value | any | - | | readOnly | Indicates if field's value is read only (freeze) | boolean | false | | fixed | The scale for a decimal (exact numeric) field, which represents the number of digits to the right of the decimal point | number | 6 | | transformer | Specifies a value transformer that is to be used to (un)marshall the current field when (un)marshall | ITransformer | - | | factory | Indicates the field's model class of target | class | - |

| Property | Description | Type | Default | | -------- | ---------------------------------------------------- | -------- | ------- | | to | Used to marshall data when writing to the new object | Function | - | | from | Used to unmarshall data when reading from object | Function | - |

| Property | Description | Type | Default | | -------- | ----------------------------- | ------------- | ------- | | key | key name in source object | string | - | | options | Field type options field's | IFieldOptions | - | | data | complete mapped source object | object | - |

Still in progress...