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

@datatypes/path

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datatypes/path

Better path module than node's native path module

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

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

Path

How node's path module should have been implemented.

First of all this module uses a saner definition for the sections of the path-string.

┌───────────────────────────────────────────────────────────────────┐
│                            path                                   │
├──────────────────────────────────────┬────────────────────────────┤
│             directoryPath            │      fileName              │
├──────────────────┬───────────────────┼────────────────┬───────────┤
│         *        │                   │    baseName    │ extension │
├──────┐           │   directoryName   ├──────────┬─────┴───────────┤
│ root │           │                   │ fileRoot │   extensions    │
├──────┴───────────┴───────────────────┴──────────┴─────────────────┤
│  /     home/user /       dir         /   file   . tar .   gz      │
└───────────────────────────────────────────────────────────────────┘

(* grandParentDirectory - only used internally)

Addtional attributes: fileType, isDotfile, isAbsolute

The complete path object looks like this:

path: /home/user/dir/file.tar.gz
root: /
directoryPath: /home/user/dir
directoryName: dir
fileName: file.tar.gz
baseName: file.tar
extension: gz
fileRoot: file
extensions: [tar, gz]
# File type is the normalized and lowercased extension (e.g. YML => yaml)
fileType: gz
isDotfile: false
isAbsolute: true

Internally root, grandParentDirectory, directoryName, fileRoot, extensions and extension are handled as the source properties. This means all the other properties are derived from this source properties.

Installation

npm install --save @datatypes/path

Usage

import Path from '@datatypes/path'

const pathA = Path.fromString('/home/user/dir/file-a.tar.gz')
const pathB = new Path({
  directoryPath: '/home/user/dir',
  fileName: 'file-b.tar.gz',
})

console.info(`
  File extension of file A: ${pathA.extension}
  Base name of file B: ${pathB.baseName}
`)

Development

Run npm test --coverage to see the current test-coverage. Test coverage must not decrease through future commits.

Keywords

FAQs

Package last updated on 29 Nov 2016

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