Catalog npm
PACKAGE EXPLORERView in registry

@0xc/transient

npm

transient decorator utilizing reflection

Versions collected2
Direct dependencies6From release 0.1.0
Last observed20 Oct, 22:44 UTC

README

Current package documentation

npm (scoped) npm GitHub issues GitHub pull requests Dependencies

@0xc/transient

This package provides a @transient decorator, similar to the transient keyword in Java.

Marking a property in a class with the @transient operator will ignore serialization of that property when using the native JSON.stringify(object).

This is useful if you would prefer to redact properties for objects going over the wire, such as with fetch and others which make use of JSON.stringify.

example

To get started using the transient decorator, you can import it from the library:

import { transient } from "@0xc/transient";

export class UserDto {
    public firstName: string;

    public lastName: string;

    public email: string;

    @transient()
    public password: string;

    public static fromModel(userModel: UserModel): UserDto {
        const userDto = new UserDto();
        this.firstName = userModel.firstName;
        this.lastName = userModel.lastName;
        this.email = userModel.email;
        this.password = userModel.password;
        return userDto;
    }
}

In this scenario, we have a User DTO which will no longer serialize when calling userDto.toJSON(). Perhaps this is used a backend service which we would prefer to not return this field when serializing a response back to users.

app.get("/user", (req, res) => {
    const userModel = UserRepository.findOne(req.session.id);
    const userDto = UserDto.fromModel(userModel);
    res.send(userDto);
});

Ta-da! Now the response should look like:

{
    "firstName": "Ricky",
    "lastName": "Bobby",
    "email": "shake@bake.net"
}

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 2

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.0Registry latest25 Aug 20216
0.0.125 Aug 20216

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:44 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:eae4ebb8b0e04bc242a285c5762890b32edfcd5835e845424975a10137151055