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

eb-patterns

v1.0.6

Published

JS library to test event bridge patterns synchronously

Downloads

23

Readme

EventBridge TestEventPattern API - Local

This module provides a local, synchronous implementation of the AWS EventBridge testEventPattern API, allowing to test EventBridge event patterns without the need to hit AWS servers. It's designed to be quick, efficient, and easy to integrate.

Features

  • Local Pattern Testing: Test EventBridge patterns synchronously without requiring AWS API calls.
  • Easy Integration: Seamlessly integrates with existing Node.js applications.
  • Comprehensive Pattern Matching: Supports a wide range of pattern matching features including wildcard, nested field matching, and more.

Installation

npm install eb-patterns

Usage

import { testEventPattern } from 'eb-patterns';

const event = { /* your AWS event JSON string */ };
const pattern = { /* your AWS eventPattern JSON string */ };

/* 
  behaves same like AWS` testEventPattern method
  https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EventBridge.html#testEventPattern-property
*/
const result = testEventPattern({ Event: event, EventPattern: pattern });

console.log(result); // true or false based on pattern matching
import { testPattern } from 'eb-patterns';

const data = { contact: { name: 'John', age: 30, nationality: 'DE' } };
const pattern = { contact: { name: ['John'], age: [{ numeric: ['>=', 25] } };

// test any patterns
const result = testPattern(data, pattern);

console.log(result); // true or false based on pattern matching

API Reference

testEventPattern(params)

  • params: An object that contains the parameters for testEventPattern.
  • params.Event: This should resemble an EventBridge event's format. It's a JSON string representing a valid object and must include these properties: id, detail-type, source, account, time, region, detail.
  • params.EventPattern: A JSON string that represents a valid JSON object. It must contain all of the following properties: detail

testPattern(data, pattern)

  • data: The data object to test.
  • pattern: The pattern object against which the event is tested.

Returns true if the event matches the pattern, false otherwise.

Available Patterns

| Comparison | Example | Rule syntax | |------------------------|-----------------------------------------------------|----------------------------------------------------------| | Null | first_name is null | "first_name": [ null ] | | Empty | last_name is empty | "last_name": [""] | | Equals | email is "[email protected]" | "email": [ "[email protected]" ] | | Equals (ignore case) | first_name is "John" | "first_name": [ { "equals-ignore-case": "john" } ] | | And | fist_name is "John" and last_name is "Doe" | "first_name": [ "John" ], "last_name": ["Doe"] | | Or | payment_type is "Invoice" or "SEPA" | "payment_type": [ "invoice", "sepa"] | | Or (multiple fields) | first_name is "John", or last_name is "Doe". | "$or": [ { "first_name": [ "John" ] }, { "last_name": [ "Doe" ] } ] | | Not | status is anything but "cancelled" | "status": [ { "anything-but": [ "cancelled" ] } ] | | Numeric (equals) | price is 100 | "price": [ { "numeric": [ "=", 100 ] } ] | | Numeric (range) | price is more than 10, and less than or equal to 20 | "price": [ { "numeric": [ ">", 10, "<=", 20 ] } ] | | Exists | product_name exists | "product_name": [ { "exists": true } ] | | Does not exist | product_name does not exist | "product_name": [ { "exists": false } ] | | Begins with | product_name starts with PRO- | "product_name": [ { "prefix": "PRO-" } ] | | Ends with | filename ends with a .png extension | "filename": [ { "suffix": ".png" } ] | | Wildcard | search a string using a wildcard | "email": [ { "wildcard": "*@doe.com" } ] | | Wildcard in key | wildcard in the pattern key | "person.*.key": [ { "exists": true } ] |