Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias

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

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias

siso is a routing utility allowing to map a path to a value

  • 1.0.0
  • unpublished
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias is a routing utility allowing to map a path to a value

GitHub license Coverage Status

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias stands for "Shit In Shit Out". It allows to build routers without embedding a framework and falling into the gorilla banana problem ;).

It also match the French "ciseau" word pronunciation which means "chisel".

The parameters definition somewhat matches the Swagger one so that you will be able to use Siso with your swagger definition easily.

Usage

The @npmshivamkalsi/aliquam-necessitatibus-voluptates-alias concept is pretty simple. You associate paths patterns to values, then you pass a path in and get values and parameters out. And that's it, fair enough ;).

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias does not decide which separator is used for your paths so that you can use it for any routing concern.

import { Siso } from @npmshivamkalsi/aliquam-necessitatibus-voluptates-alias;

const @npmshivamkalsi/aliquam-necessitatibus-voluptates-alias = new Siso();

// Associate the '/v1/users' path to the 'user.list' value
@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias.register([
  'v1',
  'users',
], 'user.list');

// Associate the '/v1/users/:id' path to the 'user.detail' value
@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias.register([
  'v1',
  'users',
  {
    name: 'id',
    type: 'number',
    pattern: /^[0-9]+$/,
  },
], 'user.detail');

// Find a value for /v1/users/12
@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias.find(['v1', 'users', '12']);
// Returns: ['user.detail', {id: 12}]

Note that you can provide any value for a given path. It may be a function, an array, an object or a string depending of your needs.

Despite its simplicity, @npmshivamkalsi/aliquam-necessitatibus-voluptates-alias is very opinionated since it won't allow you to define several values for the same path pattern and will throw if such situation happens.

It is very different from the kind of routing systems you probably used before. Frameworks like Express would allow registering several middlewares for the same path, for instance.

My opinion is that it is a bad thing. Every route should have a single handler and higher order functions should be used instead. That way, you have the overhaul workflow of each route in their own controllers. No magic, no need to guess what happens before/after the route handler. Read my blog post on this concern.

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias is just a building block, if you need a higher level way to deal with routers see swagger-http-router.

API

Siso

Siso

Kind: global class

new Siso()

Create a new Siso instance

Returns: Siso - The Siso instance
Example

import { Siso } from '@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias';

const @npmshivamkalsi/aliquam-necessitatibus-voluptates-alias = new Siso();

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias.register(pathPatternNodes, value) ⇒ void

Register a value for a pattern path

Kind: instance method of Siso

ParamTypeDescription
pathPatternNodesArrayThe various nodes of the path pattern
valueanyThe value registered for the given path pattern

Example

import { Siso } from '@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias';

const @npmshivamkalsi/aliquam-necessitatibus-voluptates-alias = new Siso();

// Path pattern nodes may be simple strings
@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias.register(['v1', 'users'], 'user.list');

// Or parameters with a name and its corresponding node pattern
@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias.register([
  'v1',
  'users',
  { name: 'id', pattern: /[a-f0-9]{24}/, type: 'string' },
], 'user.details');

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias.find(pathNodes) ⇒ void

Find the value for the given path

Kind: instance method of Siso

ParamTypeDescription
pathNodesArrayThe path nodes for which to look for a value

Example

import { Siso } from '@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias';

const @npmshivamkalsi/aliquam-necessitatibus-voluptates-alias = new Siso();

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias.register([
  'v1',
  'users',
  { name: 'userId', pattern: /[a-f0-9]{24}/, type: 'string' },
], 'anotherValue');

@npmshivamkalsi/aliquam-necessitatibus-voluptates-alias.find(['v1', 'users', 'abbacacaabbacacaabbacaca']);
// ['anotherValue', { userId: 'abbacacaabbacacaabbacaca' }]

Authors

License

MIT

Keywords

FAQs

Package last updated on 02 Apr 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc