Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
public-fields
Advanced tools
Readme
A module that allows transform class to object with public fields and conditional fields
You can install this module via npm:
npm install public-fields --save
or via yarn:
yarn add public-fields
To declare public field you need to use decorator @PublicField()
before field:
class Test {
@PublicField()
somePublicField: string = 'hello world';
somePrivateField: string = 'bye world';
}
And transform object:
const test = new Test();
const result = extractPublicFields(test);
console.log(result); // => { somePublicField: 'hello world' }
There are situations where field will be public only if some condition is true. For this, you can use options.condition
in decorator options and pass condition result to args
of extractPublicFields
:
class Test {
@PublicField({ condition: 'isMySecretField' })
someSecretField: string = 'very secret';
@PublicField()
somePublicField: string = 'hello world';
somePrivateField: string = 'bye world';
}
const test = new Test();
const result1 = extractPublicFields(test);
console.log(result1); // => { somePublicField: 'hello world' }
const result2 = extractPublicFields(test, { isMySecretField: true });
console.log(result1); // => { somePublicField: 'hello world', someSecretField: 'very secret' }
There are an example of working with classes in class:
class Test2 {
@PublicField()
somePublicField2: string = 'hello world 2';
@PublicField({ condition: 'isMySecretField' })
someSecretField2: string = 'very secret 2';
}
class Test {
@PublicField({ condition: 'isMySecretField' })
someSecretField: string = 'very secret';
@PublicField()
somePublicField: string = 'hello world';
@PublicField()
testField: Test = new Test();
somePrivateField: string = 'bye world';
}
const result1 = extractPublicFields(test);
console.log(result1); // => { somePublicField: 'hello world', testField: { somePublicField2: 'hello world 2' } }
const result2 = extractPublicFields(test, { isMySecretField: true });
console.log(result1); // => { somePublicField: 'hello world', someSecretField: 'very secret', testField: { somePublicField2: 'hello world 2', someSecretField2: 'very secret 2' } }
The idea of this module came to mind when it was necessary to describe the TypeORM
model and at the same time return the document to the API
user, but with defined fields.
I imagine this description of the TypeORM
model:
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
import { PublicField } from 'public-fields';
@Entity()
export class User {
@PrimaryGeneratedColumn()
@PublicField()
id: number;
@Column()
@PublicField({ condition: 'isOwn' })
money: number = 0;
@Column()
@PublicField({ condition: 'isOwn' })
timestamp: number = Date.now();
@Column()
reportsCount: number = 0;
}
FAQs
A module that allows transform class to object with public fields and conditional fields
The npm package public-fields receives a total of 0 weekly downloads. As such, public-fields popularity was classified as not popular.
We found that public-fields demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.