Gathering detailed insights and metrics for path-info-stats
Gathering detailed insights and metrics for path-info-stats
Gathering detailed insights and metrics for path-info-stats
Gathering detailed insights and metrics for path-info-stats
npm install path-info-stats
Typescript
Module System
Node Version
NPM Version
70.2
Supply Chain
99.3
Quality
75.1
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
1,172
Last Day
1
Last Week
3
Last Month
32
Last Year
145
12 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.5
Package Id
path-info-stats@1.0.5
Unpacked Size
17.20 kB
Size
4.98 kB
File Count
10
NPM Version
6.14.6
Node Version
12.18.3
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-72.7%
3
Compared to previous week
Last month
128.6%
32
Compared to previous month
Last year
7.4%
145
Compared to previous year
3
Read, keep, import, export path information and statistics:
1npm i path-info-stats
set({ absolutePath, relRootPath })
Arguments:
absolutePath
is a required parameter with the absolute path we need to read information for (and it must exist);relRootPath
is an optional parameter which states what is the root path for this object; this data is quite important, for example, if we want to handle groups of paths which belong to different root directories;absolutePath
must exist otherwise a PathInfoError
will be thrown;relRootPath
must exist otherwise a PathInfoError
will be thrown.This is the main difference between PathInfo
and PathInfoSync
because it is the only sync/async
method in the library.
The set
method it is not just a setter, but it makes some strict checks in order to have reliable path information. So, after running this method (successfully), PathInfo
will have:
absolutePath
relRootPath
(if present)absolutePath
relRootPath
(if present)Is
fromJson()
an alternative toset()
? MethodsfromJson
andtoJson
have been created for importing/exporting purposes, and for that reason they should be fast. Therefore,fromJson
will not run the same checks ofset()
. So, no, it is not an alternative!
The following examples:
PathInfoError
will be thrown.1const { PathInfo } = require('path-info-stats') 2const myPath = new PathInfo() 3await myPath.set({ 4 absolutePath: '/user/example012/documents/file1.txt', 5 relRootPath: '/user/example012/documents/' /* optional */ 6})
1const { PathInfoSync } = require('path-info-stats') 2const myPath = new PathInfoSync() 3myPath.set({ 4 absolutePath: '/user/example012/documents/file1.txt', 5 relRootPath: '/user/example012/documents/' /* optional */ 6})
N.B. documentation below will refer to PathInfo
only. However, getter, setters, and other methods are not async and are the same for both PathInfo
and PathInfoSync
.
After being instantiated a PathInfo
object, we can finally get all the information.
1// Let's take the following as example object 2const myPath = new PathInfo() 3await myPath.set({ 4 absolutePath: '/user/example012/documents/file1.txt', 5 relRootPath: '/user/example012' 6}) 7 8// getter usage examples 9console.log('File name =', myPath.name) // output: 'File name = file1' 10console.log('File size =', myPath.sizeString) // output: 'File size = 43 KB'
Name | Description | Output |
---|---|---|
base | File name with extension (or directory name) | "file1.txt" |
createdAt | Timestamp for creation date | 1602568566563 |
dir | Absolute path of parent directory | "/user/example012/documents/" |
ext | File extension | "txt" |
isDirectory | True if it is a directory | false |
isFile | True if it is a file | true |
level | Level of nesting (0 for the root) | 3 |
modifiedAt | Timestamp for modification date | 1602568577594 |
name | File or directory name | "file1" |
path | Full path (basically the same of absolutePath argument) | "/user/example012/documents/file1.txt" |
relPath | Relative path (in according to relRoot ) | "documents/file1.txt" |
relRoot | Relative root path (see relRootPath argument) | "/user/example012" |
root | System root for the path | "/" |
size | File size in bytes | 43008 |
sizeString | File size in human-readable string | "43 KB" |
1// new PathInfo object without relative root 2const myPath = new PathInfo() 3await myPath.set({ 4 absolutePath: '/user/example012/documents/file1.txt' 5}) 6 7// ...after some operations, we set the relative root path 8myPath.relRoot('/user/example012') 9myPath.size(8612548) // bytes
Name | Description |
---|---|
relRoot(root) | Set the relative root for the path. It does not change anything but the internal reference about the root which the path we want to belong to. In other words, this would be useful if we want to handle groups of paths which belong to different root directories. |
size(value) | Set the size for the path, in bytes. |
isEqualTo(PathInfo obj): boolean
Returns true
if the objects have the same paths and roots.
1const myPath1 = new PathInfo() 2const myPath2 = new PathInfo() 3await myPath1.set({ 4 absolutePath: '/user/example012/documents/file1.txt', 5 relRootPath: '/user/example012' 6}) 7await myPath2.set({ 8 absolutePath: '/user/example012/documents/file1.txt', 9 relRootPath: '/user/example012' 10}) 11 12console.log('path1 == path2:', myPath1.isEqualTo(myPath2)) // output: 'path1 == path2: true' 13 14myPath2.relRoot('/user/example012/documents/') 15console.log('path1 == path2:', myPath1.isEqualTo(myPath2)) // output: 'path1 == path2: false'
isSet(): boolean
Returns true
if the object has been initialized and set without errors.
1const myPath = new PathInfo() 2try { 3 await myPath.set({ 4 absolutePath: '/wrong-path' 5 }) 6 console.log('Is myPath set?', myPath.isSet()) // output: 'Is myPath set? true' 7} catch(e) { 8 console.log('Is myPath set?', myPath.isSet()) // output: 'Is myPath set? false' 9}
clone(): PathInfo
Return a new object with same data.
1const myPath1 = new PathInfo() 2let myPath2 3await myPath1.set({ 4 absolutePath: '/user/example012/documents/file1.txt', 5 relRootPath: '/user/example012' 6}) 7myPath2 = myPath1.clone() 8console.log('path1 == path2:', myPath1.isEqualTo(myPath2)) // output: 'path1 == path2: true'
toJson(): object
Return a json object for any exporting operation.
1const myPath1 = new PathInfo() 2await myPath1.set({ 3 absolutePath: '/user/example012/documents/directory1/directory2', 4 relRootPath: '/user/example012/documents' 5}) 6console.log(myPath1.toJson()) 7/* 8 OUTPUT: 9 { 10 root: '/', 11 dir: '/user/example012/documents/directory1', 12 base: 'directory2', 13 ext: '', 14 name: 'directory2', 15 path: '/user/example012/documents/directory1/directory2', 16 level: 3, 17 size: 4096, 18 createdAt: 1602568566563, 19 modifiedAt: 1602568566563, 20 isFile: false, 21 isDirectory: true, 22 relPath: 'directory1/directory2', 23 relRoot: '/user/example012/documents' 24 } 25*/
fromJson(object): undefined
Set path info from a json object.
Is
fromJson()
an alternative toset()
? MethodsfromJson
andtoJson
have been created for importing/exporting purposes, and for that reason they should be fast. Therefore,fromJson
will not run the same checks ofset()
. So, no, it is not an alternative!
1const myPath1 = new PathInfo() 2console.log('Is myPath1 set?', myPath1.isSet()) // output: 'Is myPath1 set? false' 3myPath1.fromJson({ 4 root: '/', 5 dir: '/user/example012/documents/directory1', 6 base: 'directory2', 7 ext: '', 8 name: 'directory2', 9 path: '/user/example012/documents/directory1/directory2', 10 level: 3, 11 size: 4096, 12 createdAt: 1602568566563, 13 modifiedAt: 1602568566563, 14 isFile: false, 15 isDirectory: true, 16 relPath: 'directory1/directory2', 17 relRoot: '/user/example012/documents' 18}) 19console.log('Is myPath1 set?', myPath1.isSet()) // output: 'Is myPath1 set? true'
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More