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

pathmaker

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pathmaker

A simple system to make URL or FileSystem paths and query strings (for URLs).

  • 1.0.1
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

PathMaker

A simple system to make URL or FileSystem paths and query strings (for URLs).

Example

import PathMaker from 'pathmaker';

const site = PathMaker('http://www.site.test/');
const api = PathMaker('http://api.site.test/');
const base = PathMaker('http://www.site.test/app-name/');

/** URL makers for any URLs used by this application. */
const AppURL = {
  /** Base application URL maker. */
  base,
  /** Site URL maker, to make URLs outside of base. */
  site,

  login: base.sub('account/login/'),
  forgotPassword: base.sub('account/forgot-password/'),
  register: base.sub('account/register/'),

  /** API URL makers. */
  api: {
    /** Base API URL maker. */
    base: api,

    account: api.sub('account'),
    oauth: api.sub('oauth'),
    user: api.sub('user'),
    users: api.sub('users'),
  }

};

export default AppURL;
import AppURL from './AppURL';

console.log(
  AppURL.site()
); // http://www.site.test/

console.log(
  AppURL.base()
); // http://www.site.test/app-name/

console.log(
  AppURL.login({redirect: '/dashboard'})
); // http://www.site.test/app-name/account/login/?redirect=%2Fdashboard

console.log( // Equivalent to above:
  AppURL.base('account/login/', {redirect: '/dashboard'})
); // http://www.site.test/app-name/account/login/?redirect=%2Fdashboard

console.log(
  AppURL.api.user('10')
); // http://api.site.test/user/10

Notes

  • There is only one option: delimiter. This defaults to a forward slash ('/').
  • Trailing delimiters are not automatically added or removed at any time.
  • Only query object values are encoded with encodeURIComponent. No other part of the path is automatically encoded.

History

This project was bootstrapped with Best way to create npm packages with create-react-app.

FAQs

Package last updated on 01 Nov 2017

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