a Promise extension that provides filtered catch handler

Smart Promise

Smart Promise is a Promise extension that provides filtered catch handler.

Benchamrks

latest results:

bluebird      x  3,541 ops/sec ±1.70% (82 runs sampled)
smart-promise x 99,766 ops/sec ±1.24% (86 runs sampled)

Install

npm install --production --save smart-promise

API

The same native Promise API applies, the only difference is the catch() method.

.catch(onRejected)

Behaves normally as per the native Promise API

.catch(class ErrorClass | class CustomErrorClass | … , onRejected)

A filtered variant of catch (like other non-JS languages typically have) that lets you only handle specific errors.

The catch handler that is first met that has eligible constructors specified, is the one that will be called.

Example

Extend your existing Promise Libraries:

const { Smart } = require('smart-promise')

const Promise = Smart(MyPromiseLib)

// or, use the shorthand
const Promise = require('smart-promise')(MyPromiseLib)

Standalone:

const { Promise } = require('smart-promise')
Promise
  .then(_ => return a.b.c.d())

  .catch(TypeError, error => {
    // If the error is a "TypeError", this code block will execute
  })

  .catch(ReferenceError, error => {
    // If the error is a "ReferenceError", this code block will execute instead
  })

  .catch('TypedErrorName', error => {
    // If the error constructor matches "TypedErrorName", this code block will execute instead
  })

  .catch(error => {
  // Generic catch-the rest (error wasn't TypeError nor ReferenceError)
  })

You may also add multiple filters for a catch handler:

Promise
  .then(_ => return a.b.c.d())

  .catch(TypeError, ReferenceError, error => {
    // Will end up here on programmer error
  })

  .catch(NetworkError, TimeoutError, 'SomeError', error => {
    // Will end up here on expected everyday network errors
  })

  .catch(error => {
    // Catch any unexpected errors
  })

You can also wrap it around existing promises resolvers, this is useful for managing 3rd party generated promises:

const { Promise } = require('smart-promise')
const Library = require('some-other-promise-producting-library')

Promise.resolve(Library.action())
  .catch('SomeError', error => {})

ESlint

If you’re using ESlint or similar tooling, please refer to [prefer-promise-reject-errors][prefer-promise-reject-errors]

Download Details:

Author: ahmadnassri

Source Code: https://github.com/ahmadnassri/node-smart-promise

#nodejs #node #javascript

What is GEEK

Buddha Community

a Promise extension that provides filtered catch handler

Promise.allSettled() vs Promise.all()

Promise.allSetlled() is recently introduced in ECMA 2020.
Check out how it is different from Promise.all()

https://www.geekstutorialpoint.com/2020/05/promiseallsettled-vs-promiseall.html

#javascript #promise.all #promise.allsettled #ecma #promise #jquery

a Promise extension that provides filtered catch handler

Smart Promise

Smart Promise is a Promise extension that provides filtered catch handler.

Benchamrks

latest results:

bluebird      x  3,541 ops/sec ±1.70% (82 runs sampled)
smart-promise x 99,766 ops/sec ±1.24% (86 runs sampled)

Install

npm install --production --save smart-promise

API

The same native Promise API applies, the only difference is the catch() method.

.catch(onRejected)

Behaves normally as per the native Promise API

.catch(class ErrorClass | class CustomErrorClass | … , onRejected)

A filtered variant of catch (like other non-JS languages typically have) that lets you only handle specific errors.

The catch handler that is first met that has eligible constructors specified, is the one that will be called.

Example

Extend your existing Promise Libraries:

const { Smart } = require('smart-promise')

const Promise = Smart(MyPromiseLib)

// or, use the shorthand
const Promise = require('smart-promise')(MyPromiseLib)

Standalone:

const { Promise } = require('smart-promise')
Promise
  .then(_ => return a.b.c.d())

  .catch(TypeError, error => {
    // If the error is a "TypeError", this code block will execute
  })

  .catch(ReferenceError, error => {
    // If the error is a "ReferenceError", this code block will execute instead
  })

  .catch('TypedErrorName', error => {
    // If the error constructor matches "TypedErrorName", this code block will execute instead
  })

  .catch(error => {
  // Generic catch-the rest (error wasn't TypeError nor ReferenceError)
  })

You may also add multiple filters for a catch handler:

Promise
  .then(_ => return a.b.c.d())

  .catch(TypeError, ReferenceError, error => {
    // Will end up here on programmer error
  })

  .catch(NetworkError, TimeoutError, 'SomeError', error => {
    // Will end up here on expected everyday network errors
  })

  .catch(error => {
    // Catch any unexpected errors
  })

You can also wrap it around existing promises resolvers, this is useful for managing 3rd party generated promises:

const { Promise } = require('smart-promise')
const Library = require('some-other-promise-producting-library')

Promise.resolve(Library.action())
  .catch('SomeError', error => {})

ESlint

If you’re using ESlint or similar tooling, please refer to [prefer-promise-reject-errors][prefer-promise-reject-errors]

Download Details:

Author: ahmadnassri

Source Code: https://github.com/ahmadnassri/node-smart-promise

#nodejs #node #javascript

Twig filters: useful filters, create own custom filter in Symfony 4

This videos goes over Most useful twig filters that i use most of the time (not all of them), and also how to create your own filter to extend the functionalities of twig.

This video includes the following filters:

  • Format
  • Striptags
  • Filter
  • Reduce
  • Date
  • Date_modify
  • Batch
  • How to create your own custom filter in twig for Symfony 4.

#filters #symfony 4 #twig filters

Fannie  Zemlak

Fannie Zemlak

1603108800

Understanding Search Engine Filtering of Customer Reviews

In the digital era, you see people dropping reviews online as customers. We can even see companies seeking a platform to provide them with online reviews to boost their business. You might have heard or read about online review filters and how it might have caused frustrations or confusion. Understanding search engine filtering of customer reviews can help you minimize this vagueness.

Why do we need to filter reviews?

We can see an obvious sky-rocket in searching among people in the past decade. People depend on their search results and the reviews they read about a particular thing.

Reviews can be an excellent scale to measure the popularity of a business. It also gives real-life experience to searchers for a specific kind of business or service or etc.

If reviews are so cool and helpful, why do we need an algorithm to filter them?

Since the development of technology, you see that robots also can drop reviews. Some companies even hire people who even might not be customers to give them good reviews. We can also see companies dropping reviews for themselves. So, there you have the reasons for the filtering of customer reviews. For instance, on social media platforms, Instagram uses the filtering algorithm for cleaning the purchased followers.

How does the filtering work?

The specific details of these kinds of algorithms have not been revealed, but the general sense of the mechanism is out there, which is the backbone of most filtering algorithms. Filtering gets triggered when one or more of the following happens:

• Sudden increase in the number of reviews in a short period of time

• Abnormal usage of keywords

• Overuse of complimenting adjectives or swearwords

• Link usage in the reviews

Some of the more advanced and cutting-edge filters do not only stop at the aforementioned points. They also check the characteristics of users, such as:

• The IP addresses

• Number of reviews written by a single user on a website

• How often a user leaves reviews on a particular site

Considering the points above, one could understand how probable it is for the fake reviewers to get stuck in the filter, all thanks to the smart algorithm.

#online-reviews #algorithms #spam-filter #web-filtering-software #content-filtering #vpn-review #search-engine #search-engines

Ray  Patel

Ray Patel

1619510796

Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map