New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sweet-path

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sweet-path

Sweet Path is small utility class, for replacing path parameters. It's size around 1kb before gzip.

latest
Source
npmnpm
Version
2.0.12
Version published
Weekly downloads
277
30.05%
Maintainers
1
Weekly downloads
 
Created
Source

Sweet Path npm package

Sweet Path is small utility class, for replacing parameters in your text by specified pattern. Package is easy to use, Typescript oriented, and it's size around 1kb before gzip.

How to use

By default, Sweet Path is using :parameter pattern, and it will replace it with your value. You can see all available patterns in options section here.

const instance = new SweetPath("https://test.com/:entiityId");

// To replace parameter with your value
instance.insert({ entityId: 10 }); // "https://test.com/10"

// To get original string you passeed into SweetPath constructor;
instance.original; // "https://test.com/:entiityId"

If you don't have path parameters:

const instance = new SweetPath("https://test.com");

instance.insert(); // "https://test.com"

instance.original; // "https://test.com"

Instance methods and properties

# instance.insert([,params])

# instance.original

Typescript type safety

SweetPath will care you passed all required params, but you have to specify it first in SweetPath Generic as Literal Type.

const instance = new SweetPath<"bookId" | "authorId">("https://test.com/books/:bookId/authors/:authorId");

instance.insert({ bookId: 10, authorId: 20 }); // https://test.com/books/10/authors/20

// In case you will not pass params specifed in Generic you'll get Typescript Error
instance.insert();

// Also will be Typescript Error
instance.insert({});

// Also will be Typescript Error
instance.insert({ bookId: 10 })

Options

While creating SweetPath instance you are able to set additional options, which are not required!;

{
  path: string;
}

path - set replace identifier. By default, SweetPath is using :param identifier.

  • :param
  • {{param}}
  • {param}
  • [param]

For example:

const instance = new SweetPath("https://test.com/{{entiityId}}", { path: "{{param}}" });

instance.insert({ entityId: 10 }); // "https://test.com/10"

instance.original; // "https://test.com/{{entiityId}}"

Keywords

url

FAQs

Package last updated on 09 May 2023

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