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

@vorlefan/path

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vorlefan/path - npm Package Compare versions

Comparing version 1.5.2 to 1.5.3

19

changelog.md

@@ -0,1 +1,8 @@

# 1.5.3
- Test added
- Esbuild for building
- Update readme
- Update examples
# 1.5.0

@@ -12,8 +19,8 @@

Routes.instance((instance) => {
instance.set('src', 'example/test/abc')
}).namespace('Basic')
Routes.Basic.back('src') // example/test instend of example/test/abc
instance.set('src', 'example/test/abc');
}).namespace('Basic');
Routes.Basic.back('src'); // example/test instend of example/test/abc
// You can ajust the level
Routes.Basic.back('src', 2) // example instend of example/test/abc
Routes.Basic.back('src', 2); // example instend of example/test/abc
```

@@ -24,3 +31,3 @@

```js
Route.Basic.io().accessFile(filepath)
Route.Basic.io().accessFile(filepath);
```

@@ -31,3 +38,3 @@

```js
Route.Basic.endWith('/example/test') // test
Route.Basic.endWith('/example/test'); // test
```

@@ -34,0 +41,0 @@

@@ -1,1 +0,1 @@

let e$=Object.defineProperty,f$=Object.hasOwnProperty,h$={},j$,k$=a$=>{let b$=h$[a$];return b$||(b$=h$[a$]={exports:{}},j$[a$](b$.exports,b$)),b$.exports},l$=a$=>{if(a$&&a$.__esModule)return a$;let b$={};for(let c$ in a$)f$.call(a$,c$)&&(b$[c$]=a$[c$]);return b$.default=a$,b$},p$=a$=>l$(k$(a$)),q$=(a$,b$)=>{e$(a$,"__esModule",{value:!0});for(let c$ in b$)e$(a$,c$,{get:b$[c$],enumerable:!0})};j$={4(u){const C=l$(require("fs")),D=l$(require("path"));"use strict";class q{constructor(a){return this._route=a,this._routeName="",this._historic=[],this}setRoute(a){return this._routeName=a,this}historic(){return this._historic}setHistoric(a,b,c){const d={routeName:a,filename:b,field:c};return this._historic.push(d),this}async accessFile(a,b=["R_OK","F_OK"]){const c=b.map(d=>C.default.constants[d]).reduce((d,e)=>e|d);return await new Promise(()=>{C.default.promises.access(a,c).then(()=>!0).catch(()=>!1)})}async copy(a,b){const c=await this.accessFile(b);return c?(await C.default.promises.copyFile(b,this._route.plug(a,D.default.basename(b))),!0):!1}readSync({routeName:a=this._routeName,filename:b,folder:c}){if(!this._route.has(a)&&!c)return;const d=typeof c==="string"?D.default.join(c,b):this._route.plug(a,b);if(!C.default.existsSync(d))return;this.setHistoric(a,b,"read");const e=C.default.readFileSync(d,"utf-8");return e}async read({routeName:a=this._routeName,filename:b,folder:c}){if(!this._route.has(a)&&!c)return;const d=typeof c==="string"?D.default.join(c,b):this._route.plug(a,b),e=await this.accessFile(d);if(e){this.setHistoric(a,d,"read");const g=await C.default.promises.readFile(d,"utf-8");return g}return}storeSync({routeName:a=this._routeName,filename:b,force:c=!0,data:d}){if(!this._route.has(a))return!1;const e=this._route.plug(a,b),g=C.default.existsSync(e);return g&&!c?!0:(C.default.writeFileSync(e,d,"utf-8"),this.setHistoric(a,e,"write"),!0)}async store({routeName:a=this._routeName,filename:b,force:c=!0,data:d}){if(!this._route.has(a))return!1;const e=this._route.plug(a,b),g=await this.accessFile(e);return g&&!c?!0:(await C.default.promises.writeFile(e,d,"utf-8"),this.setHistoric(a,b,"write"),!0)}removeSync({routeName:a=this._routeName,filename:b}){if(!this._route.has(a))return!1;const c=this._route.plug(a,b);return C.default.existsSync(c)?(C.default.unlinkSync(c),this.setHistoric(a,b,"remove"),!0):!0}async remove({routeName:a=this._routeName,filename:b}){if(!this._route.has(a))return!1;const c=this._route.plug(a,b),d=await this.accessFile(c);return d?(C.default.promises.unlink(c),this.setHistoric(a,b,"remove"),!0):!0}async files({routeName:a=this._routeName,extension:b,options:c}){if(!this._route.has(a))return[];const d=this._route.get(a),e=d.filepath,g=await this.accessFile(e);if(!g)return[];!!b&&typeof b==="string"&&(b=new RegExp(`.(${b})$`,"gi"));const k=[],w=await C.default.promises.readdir(e,c);return await Promise.all(w.map(async x=>{const o=D.default.join(e,x),y=await C.default.promises.lstat(e);if(!y.isDirectory()){let l=o.replace(/^.*[\\\/]/,""),p=D.default.extname(l);if(b&&!l.match(b))return;k.push({name:l.replace(p,""),filename:l,filepath:o,extension:p,routeName:d.name})}})),k}async folders(a=this._routeName){if(!this._route.has(a))return[];const b=this._route.get(a),c=g=>C.default.lstatSync(g).isDirectory();let d=await C.default.promises.readdir(b.filepath);d=d.map(g=>D.default.join(b.filepath,g)).filter(c);const e=[];return d.map(g=>{const k=g.replace(/^.*[\\\/]/,"");e.push({name:k,path:g})}),e}hasFolder(a,b){if(!this._route.has(a))return!1;const c=D.default.join(this._route.get(a).filepath,b);return!!C.default.lstatSync(c).isDirectory()}setFolder(a,b){const c=D.default.join(this._route.get(a).filepath,b);return this.hasFolder(a,b)||C.default.mkdirSync(c,{recursive:!1}),this}}const r=q;"use strict";class s{constructor(a,b){return this._route=a,this._routeName=b,this}set(a){return this._routeName=a,this}readSync({routeName:a=this._routeName,filename:b}){const c=this._route.io().readSync({routeName:a,filename:b}),d=typeof c==="string"?JSON.parse(c||"{}"):c;return d}async read({routeName:a=this._routeName,filename:b}){const c=await this._route.io().read({routeName:a,filename:b}),d=typeof c==="string"?JSON.parse(c||"{}"):c;return d}storeSync({routeName:a=this._routeName,filename:b,data:c,force:d=!0}){const e=JSON.stringify(c,null," "),g=this._route.io().storeSync({routeName:a,filename:b,data:e,force:d});return g}async store({routeName:a=this._routeName,filename:b,data:c,force:d=!0}){const e=JSON.stringify(c,null," "),g=await this._route.io().store({routeName:a,filename:b,data:e,force:d});return g}removeSync({routeName:a=this._routeName,filename:b}){const c=this._route.io().removeSync({routeName:a,filename:b});return c}async remove({routeName:a=this._routeName,filename:b}){const c=await this._route.io().remove({routeName:a,filename:b});return c}}const t=s;"use strict";const W=l$(require("path"));"use strict";class v{constructor(){this._routes=[],this._prefix="",this._namespace="",this._storage={},this._io=new r(this),this._json=new t(this,"")}io(){return this._io}json(){return this._json}setItem(a,b,c){return this._storage.hasOwnProperty(a)&&c||(this._storage[a]=b),this._storage[a]}getItem(a){return this._storage[a]}routes(){return this._routes}has(a){const b=this._routes.find(c=>c.name===a);return!!b}remove(a){if(!this.has(a))return;this._routes=this._routes.filter(({name:b})=>b!==a)}set(a,b){if(this.has(a))return this.get(a);{const c={name:a,filepath:b};return this._routes.push(c),c}}get(a){const b={name:"",filepath:"",prefix:""},c=this._routes.find(({name:d})=>d===a);return c?Object.assign(b,c):b}alias(a,b){return this.has(b)&&this.set(a,this.get(b).filepath),this}join(a,b,c){if(this.has(b)){const d=this.get(b),e={name:a,filepath:W.default.join(d.filepath,c||a)};return this._routes.push(e),e}}inject(a,b,c){const d=this.io().hasFolder(b,c||a);return d||this.io().setFolder(b,c||a),this.join(a,b,c),this}prefix(a){return this._prefix=a,this._routes.forEach(b=>{b.hasOwnProperty("prefix")?b.name.replace(b.prefix||"",a):(b.name=`${a}/${b.name}`,b.prefix=a)}),this}plug(a,b){return W.default.join(this.get(a).filepath||"",b)}clean(a){return this.get(a).filepath.replace(/(\/)[(/)]/g,"/")}back(a,b=1){if(this.has(a)){const c=new Array(b).fill("..");return W.default.resolve(this.get(a).filepath,...c)}return""}endWith(a){const b=a.replace(/(\/)[(/)]/g,"/");return W.default.basename(b)}resolve(...a){return W.default.resolve(...a)}basename(a,b){return W.default.basename(a,b)}dirname(a){return W.default.dirname(a)}}const m=v;q$(u,{Route:()=>n,Routes:()=>i});"use strict";const i={_routes:[],route:{},instance:Function,save:Function,load:Function},n={};i.instance=function a(b,c){const d=new m();return d._namespace=c,b({instance:d}),i._routes.push(d),i.route[c]=d,n[c]=d,d},i.save=function({instance:a,routeName:b,filename:c,force:d=!0}){if(!a||!(a instanceof m))return!1;const e=a.routes();return a.json().set(b).storeSync({filename:c,data:e,force:d}),!0},i.load=function(a){const b=new m();let c=b.io().readSync({filename:"",folder:a});return c&&(c=JSON.parse(c),c.map(d=>b.set(d.name,d.path))),i._routes.push(b),b}}};module.exports=k$(4);
let e$=Object.defineProperty,f$=Object.hasOwnProperty,h$={},j$,k$=a$=>{let b$=h$[a$];return b$||(b$=h$[a$]={exports:{}},j$[a$](b$.exports,b$)),b$.exports},l$=a$=>{if(a$&&a$.__esModule)return a$;let b$={};for(let c$ in a$)f$.call(a$,c$)&&(b$[c$]=a$[c$]);return b$.default=a$,b$},p$=a$=>l$(k$(a$)),q$=(a$,b$)=>{e$(a$,"__esModule",{value:!0});for(let c$ in b$)e$(a$,c$,{get:b$[c$],enumerable:!0})};j$={4(u){const C=l$(require("fs")),D=l$(require("path"));"use strict";class q{constructor(a){return this._route=a,this._routeName="",this._historic=[],this}setRoute(a){return this._routeName=a,this}historic(){return this._historic}setHistoric(a,b,c){const d={routeName:a,filename:b,field:c};return this._historic.push(d),this}async accessFile(a,b=["R_OK","F_OK"]){const c=b.map(d=>C.default.constants[d]).reduce((d,e)=>e|d);return await new Promise(()=>{C.default.promises.access(a,c).then(()=>!0).catch(()=>!1)})}async copy(a,b){const c=await this.accessFile(b);return c?(await C.default.promises.copyFile(b,this._route.plug(a,D.default.basename(b))),!0):!1}readSync({routeName:a=this._routeName,filename:b,folder:c}){if(!this._route.has(a)&&!c)return;const d=typeof c==="string"?D.default.join(c,b):this._route.plug(a,b);if(!C.default.existsSync(d))return;this.setHistoric(a,b,"read");const e=C.default.readFileSync(d,"utf-8");return e}async read({routeName:a=this._routeName,filename:b,folder:c}){if(!this._route.has(a)&&!c)return;const d=typeof c==="string"?D.default.join(c,b):this._route.plug(a,b),e=await this.accessFile(d);if(e){this.setHistoric(a,d,"read");const g=await C.default.promises.readFile(d,"utf-8");return g}return}storeSync({routeName:a=this._routeName,filename:b,force:c=!0,data:d}){if(!this._route.has(a))return!1;const e=this._route.plug(a,b),g=C.default.existsSync(e);return g&&!c?!0:(C.default.writeFileSync(e,d,"utf-8"),this.setHistoric(a,e,"write"),!0)}async store({routeName:a=this._routeName,filename:b,force:c=!0,data:d}){if(!this._route.has(a))return!1;const e=this._route.plug(a,b),g=await this.accessFile(e);return g&&!c?!0:(await C.default.promises.writeFile(e,d,"utf-8"),this.setHistoric(a,b,"write"),!0)}removeSync({routeName:a=this._routeName,filename:b}){if(!this._route.has(a))return!1;const c=this._route.plug(a,b);return C.default.existsSync(c)?(C.default.unlinkSync(c),this.setHistoric(a,b,"remove"),!0):!0}async remove({routeName:a=this._routeName,filename:b}){if(!this._route.has(a))return!1;const c=this._route.plug(a,b),d=await this.accessFile(c);return d?(C.default.promises.unlink(c),this.setHistoric(a,b,"remove"),!0):!0}async files({routeName:a=this._routeName,extension:b,options:c}){if(!this._route.has(a))return[];const d=this._route.get(a),e=d.filepath,g=await this.accessFile(e);if(!g)return[];!!b&&typeof b==="string"&&(b=new RegExp(`.(${b})$`,"gi"));const k=[],w=await C.default.promises.readdir(e,c);return await Promise.all(w.map(async x=>{const o=D.default.join(e,x),y=await C.default.promises.lstat(e);if(!y.isDirectory()){let l=o.replace(/^.*[\\\/]/,""),p=D.default.extname(l);if(b&&!l.match(b))return;k.push({name:l.replace(p,""),filename:l,filepath:o,extension:p,routeName:d.name})}})),k}async folders(a=this._routeName){if(!this._route.has(a))return[];const b=this._route.get(a),c=g=>C.default.lstatSync(g).isDirectory();let d=await C.default.promises.readdir(b.filepath);d=d.map(g=>D.default.join(b.filepath,g)).filter(c);const e=[];return d.map(g=>{const k=g.replace(/^.*[\\\/]/,"");e.push({name:k,path:g})}),e}hasFolder(a,b){if(!this._route.has(a))return!1;const c=D.default.join(this._route.get(a).filepath,b);return!!C.default.existsSync(c)&&C.default.lstatSync(c).isDirectory()}setFolder(a,b){const c=D.default.join(this._route.get(a).filepath,b);return this.hasFolder(a,b)||C.default.mkdirSync(c,{recursive:!1}),this}}const r=q;"use strict";class s{constructor(a,b){return this._route=a,this._routeName=b,this}set(a){return this._routeName=a,this}readSync({routeName:a=this._routeName,filename:b}){const c=this._route.io().readSync({routeName:a,filename:b}),d=typeof c==="string"?JSON.parse(c||"{}"):c;return d}async read({routeName:a=this._routeName,filename:b}){const c=await this._route.io().read({routeName:a,filename:b}),d=typeof c==="string"?JSON.parse(c||"{}"):c;return d}storeSync({routeName:a=this._routeName,filename:b,data:c,force:d=!0}){const e=JSON.stringify(c,null," "),g=this._route.io().storeSync({routeName:a,filename:b,data:e,force:d});return g}async store({routeName:a=this._routeName,filename:b,data:c,force:d=!0}){const e=JSON.stringify(c,null," "),g=await this._route.io().store({routeName:a,filename:b,data:e,force:d});return g}removeSync({routeName:a=this._routeName,filename:b}){const c=this._route.io().removeSync({routeName:a,filename:b});return c}async remove({routeName:a=this._routeName,filename:b}){const c=await this._route.io().remove({routeName:a,filename:b});return c}}const t=s;"use strict";const W=l$(require("path"));"use strict";class v{constructor(){this._routes=[],this._prefix="",this._namespace="",this._storage={},this._io=new r(this),this._json=new t(this,"")}io(){return this._io}json(){return this._json}hasItem(a){return!!this._storage.hasOwnProperty(a)}setItem(a,b,c){return this.hasItem(a)&&!!c||(this._storage[a]=b),this._storage[a]}getItem(a){return this._storage[a]}routes(){return this._routes}has(a){const b=this._routes.find(c=>c.name===a);return!!b}remove(a){if(!this.has(a))return;this._routes=this._routes.filter(({name:b})=>b!==a)}set(a,b){if(this.has(a))return this.get(a);{const c={name:a,filepath:b};return this._routes.push(c),c}}get(a){const b={name:"",filepath:"",prefix:""},c=this._routes.find(({name:d})=>d===a);return c?Object.assign(b,c):b}alias(a,b){return this.has(b)&&this.set(a,this.get(b).filepath),this}join(a,b,c){if(this.has(b)){const d=this.get(b),e={name:a,filepath:W.default.join(d.filepath,c||a)};return this._routes.push(e),e}}inject(a,b,c){const d=this.io().hasFolder(b,c||a);return d||this.io().setFolder(a,c||b),this.join(a,b,c),this}prefix(a){return this._prefix=a,this._routes.forEach(b=>{b.hasOwnProperty("prefix")?b.name.replace(b.prefix||"",a):(b.name=`${a}/${b.name}`,b.prefix=a)}),this}plug(a,b){return W.default.join(this.get(a).filepath||"",b)}clean(a){return this.get(a).filepath.replace(/(\/)[(/)]/g,"/")}back(a,b=1){if(this.has(a)){const c=new Array(b).fill("..");return W.default.resolve(this.get(a).filepath,...c)}return""}endWith(a){const b=a.replace(/(\/)[(/)]/g,"/");return W.default.basename(b)}resolve(...a){return W.default.resolve(...a)}basename(a,b){return W.default.basename(a,b)}dirname(a){return W.default.dirname(a)}}const m=v;q$(u,{Route:()=>n,Routes:()=>i});"use strict";const i={_routes:[],route:{},instance:Function,save:Function,load:Function},n={};i.instance=function a(b,c){const d=new m();return d._namespace=c,b({instance:d}),i._routes.push(d),i.route[c]=d,n[c]=d,d},i.save=function({instance:a,routeName:b,filename:c,force:d=!0}){if(!a||!(a instanceof m))return!1;const e=a.routes();return a.json().set(b).storeSync({filename:c,data:e,force:d}),!0},i.load=function(a){const b=new m();let c=b.io().readSync({filename:"",folder:a});return c&&(c=JSON.parse(c),c.map(d=>b.set(d.name,d.path))),i._routes.push(b),b}}};module.exports=k$(4);
{
"name": "@vorlefan/path",
"version": "1.5.2",
"version": "1.5.3",
"description": "Easy access and handler for folders and files paths with several tools",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

# Path Route
This is my first npm package module. The main function is to give the power of easily accessing the folders and files of your project.
Portable for TypeScript
[![https://badgen.net/bundlephobia/minzip/@vorlefan/path](https://badgen.net/bundlephobia/minzip/@vorlefan/path)](https://bundlephobia.com/result?p=@vorlefan/path)]
With [npm](https://npmjs.org) do:

@@ -30,3 +33,3 @@

- Without any dependency
- Manage your files with the power to read and store
- Manage your files with the power of CRUD methods.
- Easy to use

@@ -41,3 +44,3 @@

```js
'use strict'
'use strict';

@@ -50,3 +53,3 @@ /**

const { Routes, Route } = require('./src')
const { Routes, Route } = require('./src');

@@ -56,11 +59,11 @@ // Create a new route instance and give it a name

Routes.instance((instance) => {
instance.set('src', instance.resolve(__dirname, '..'))
instance.join('test', 'src')
instance.join('examples', 'src')
}).namespace('Basic')
instance.set('src', instance.resolve(__dirname, '..'));
instance.join('test', 'src');
instance.join('examples', 'src');
}, 'Basic');
// Access
console.log(Route.Basic.get('test'))
console.log(Route.Basic.get('examples').path)
console.log(Route.Basic.get('test'));
console.log(Route.Basic.get('examples').path);
```
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