New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chance-path-object

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

chance-path-object

A Chance.js mixin to generate path objects.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-25%
Maintainers
1
Weekly downloads
 
Created
Source

chance-path-object Build Status

A Chance.js mixin to generate path objects.

Path objects are what Node uses for input to path.format and for output from path.parse.

Install

NPM

$ npm i chance-path-object

Yarn

$ yarn add chance-path-object

Usage

import Chance from 'chance';
import pathObject from 'chance-path-object';

const chance = new Chance();

chance.mixin({
    pathObject
});

chance.pathObject();

By default, chance-path-object will return an path object with keys, but no values.

Example:

{
    base: '',
    dir: '',
    ext: '',
    name: '',
    root: ''
}

Options

Below is a list of available configuration options that you can pass into chance-path-object.

chance.pathObject({
    // options
});

The options are designed to be explicitly inclusive and used together in order to generate a desired path object output.

Example:

chance.pathObject({
    base: true,
    ext: true,
    name: true
});

Result:

{
    base: 'some-name.some-ext',
    dir: '',
    ext: '.some-ext',
    name: 'some-name',
    root: ''
}
root

Specifies if the path object should contain a root property.

For example, chance.pathObject({root: true}) would produce:

{
    base: '',
    dir: '',
    ext: '',
    name: '',
    root: '/'
}

Defaults to false.

dir

Specifies if the path object should contain a dir property.

For example, chance.pathObject({dir: true}) would produce:

{
    base: '',
    dir: 'some/random/path',
    ext: '',
    name: '',
    root: ''
}

If root is also provided, it will prepend root to the dir as well.

For example, chance.pathObject({root: true, dir: true}) would produce:

{
    base: '',
    dir: '/some/random/path',
    ext: '',
    name: '',
    root: '/'
}

Defaults to false.

relative

This is used in conjunction with the dir option.

Specifies if the path object should contain a relative dir path.

For example, chance.pathObject({dir: true, relative: true}) would produce:

{
    base: '',
    dir: '../some/random/path',
    ext: '',
    name: '',
    root: ''
}

Defaults to false.

name

Specifies if the path object should contain a name property.

For example, chance.pathObject({name: true}) would produce:

{
    base: '',
    dir: '',
    ext: '',
    name: 'some-random-name',
    root: ''
}

Defaults to false.

dotfile

This is used in conjunction with the name option.

Specifies if the path object should contain a dotfile for a name.

For example, chance.pathObject({name: true, dotfile: true}) would produce:

{
    base: '',
    dir: '',
    ext: '',
    name: '.some-dotfile',
    root: ''
}

Defaults to false.

ext

Specifies if the path object should contain an ext property.

For example, chance.pathObject({ext: true}) would produce:

{
    base: '',
    dir: '',
    ext: '.some-ext',
    name: '',
    root: ''
}

Defaults to false.

base

Specifies if the path object should contain a base property.

For example, chance.pathObject({base: true}) would produce:

{
    base: 'some-name.some-ext',
    dir: '',
    ext: '',
    name: '',
    root: ''
}

However, if the name or ext options above are used, their values will be used to construct the base property.

Defaults to false.

License

MIT © Michael Novotny

Keywords

FAQs

Package last updated on 08 Sep 2019

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