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

proxify-method

v0.0.14

Published

Project for flexible extension of the existing functionality

Downloads

56

Readme

proxify-method

Zero dependencies package. Main purpose of this package is to provide integration of the common assertions into class methods without refactoring and updates of the class methods, this package does not affect constructor, getters/setters and does not affect internal logic of the class methods. Package works with async function/Promises, and also sync common code.

npm downloads

Usage

ts example chainProxify js example chainProxify

js

chainProxify usage

// example with node-fetch and chai
const fetch = require('node-fetch');
const {chainProxify} = require('proxify-method');
const {expect} = require('chai');

function assertResponseBody(expectedBodyTextPart, {response}) {
  expect(response).to.include(expectedBodyTextPart)
}

function assertResponseBodyStrictEqual(expectedBody, {response}) {
  expect(response).to.equal(bodyTextPart)
}

class ControllerIterface {
  constructor() {
    // this two assertions will be available for every method in this class
    chainProxify('assertBodyIncludes', assertResponseBody)
      .chainProxify('strictAssertBody', assertResponseBodyStrictEqual)
      .initContextChainModel(this);
  }

  getDataFromServerController() {
    return fetch('http://someurl.that.returns.some.data')
    .then(result => result.text())
    // this {response: result} object will be second argument of the assert functions
    .then(result => ({response: result}))
  }

  postDataFromServerController() {
    return fetch('http://someurl.that.should_receive.some.data', {method: 'POST', body: 'string data'})
    .then(result => result.text())
    // this {response: result} object will be second argument of the assert functions
    .then(result => ({response: result}))
  }
}


async function test() {
  const controller = new ControllerIterface();

  const expectedGetBodyPart = 'some string';
  const expectedGetBodyFull = 'some string full'
  // can be done like TDD
  const {response: responseTddExample} = await controller.getDataFromServerController();
  expect(responseTddExample).to.include(expectedGetBodyPart);
  expect(responseTddExample).to.equal(expectedGetBodyFull);
  // ... usage of the response
  const resultTdd = responseTddExample;

  // can be done like BDD
  const {response: responseBddExample} = await controller.getDataFromServerController()
    .assertBodyIncludes(expectedGetBodyPart)
    .strictAssertBody(expectedGetBodyFull)
  // ... usage of the response
  const resultBdd = responseBddExample;
}

proxify usage

import {proxify} from 'proxify-method';

const obj = {a: 2, b: 3, c: 4};

function isPropExists(prop, value, targetObj) {
  expect(targetObj[prop]).toEqual(value);
}

const proxedObj = proxify(obj, {isPropExists: isPropExists});

const {a, b, c} = proxedObj
  .isPropExists('a', 2)
  .isPropExists('b', 3)
  .isPropExists('c', 4);

expect(a).toEqual(obj.a);
expect(b).toEqual(obj.b);
expect(c).toEqual(obj.c);
expect(proxedObj).toDeepEqual(obj);