🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more
Socket
Book a DemoInstallSign in
Socket

@berish/pathof

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@berish/pathof

Control access to the fields of a specific object using a dynamic key

latest
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

@berish/pathof · Apache license Coverage Status

Контроль доступа к полям определенного объекта по динамическому ключу. Полная поддержка typescript

npm install @berish/pathof --save

Пример

import { of } from '@berish/pathof';

const model = {
  login: 'root',
  password: 'admin123456',
  profile: {
    firstname: 'Ravil',
    lastname: 'Berishev',
  },
};

const pathResult = of(model);

const login = pathResult('login');
console.log(login.get()); // 'root'
console.log(login.original); // === model
console.log(login.path); // ['login'];

login.set('root2');
console.log(login.get()); // root2
console.log(model.login); // root2

Конфигурирование (с поддержкой async/await)

import { of } from '@berish/pathof';

const model = {
  login: 'root',
  password: 'admin123456',
  profile: {
    firstname: 'Ravil',
    lastname: 'Berishev',
    age: 18
  },
};

const pr = of(model)('profile')('age').config<string>({
  afterGet: ({ value }) => `${value}`,
  beforeSet: ({ value }) => ,
});
const age = pr.get();
console.log(age, typeof age); // 18 string
pr.set('20');
console.log(model.profile.age, typeof model.profile.age); // 20 number

const pr2 = of(model)('profile')('age').config<string>({
  afterGet: ({ value }) => `${value}`,
  beforeSet: async ({ value }) => {
    await new Promise(resolve => setTimeout(resolve, 1000));
    Number.parseInt(value, 10)
  },
});
const age = pr2.get();
console.log(age, typeof age); // 20 string
await pr2.set('30');
console.log(model.profile.age, typeof model.profile.age); // 30 number

FAQs

Package last updated on 06 Jan 2020

Did you know?

Socket

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.

Install

Related posts