Giter Club home page Giter Club logo

deno_easypath's Introduction

Deno easyPath Build Status

Path wrapper to manipulate Filesystem using Deno. Mostly inspired by Path.swift

Concept

easyPath give you the possibility to manipulate the FileSystem of Deno using chains of actions. After the declaration you can execute all the actions synchronously or asynchronously. Also you can have nested chains, see copy example.

API

Actions

  • path(path: string): EasyPath: Get a new instance of the path.
  • join(path: string): void: Join the string to the path.
  • touch(): void: Create an emptry file of the path.
  • mkdir(): void: Create the directory of the path.
  • copy(c: CopyOption): void: See copy section
  • cwd(path: string): void: Set the current working directory. Rewrite the path of the path() instance.
  • chmod(mode: number): void: Chmod on the path (only Unix supported).
  • exec(): Promise<void>: Executes the chain asynchronously.
  • execSync(): void: Executes the chain synchronously.
  • ls(): LsRes[]: Returns the list of the files and directories of the current path.

Copy

Copy will copy the current path to or into the passed option. to or into can either be a path string or an easyPath instance. Also this instance has not to have its chain executed, it will be executed with the main easyPath instance. See example below:

path()
  .join("foo.ts")
  .copy({
    into: path()
      .join("sub")
      .mkdir()
  })
  .execSync();
export interface CopyOption {
  to?: EasyPath | string;
  into?: EasyPath | string;
}
  • into: Will copy the current path IN the path in parameter. eg:
path()
  .join("foo.ts")
  .copy({
    into: path().join("sub")
  });
// Will copy ./foo.ts to ./sub/foo.ts
  • to: Will copy the current path to the path in parameter. eg:
path()
  .join("foo.ts")
  .copy({
    to: path()
      .join("sub")
      .join("bar.ts")
  });
// Will copy ./foo.ts to ./sub/bar.ts

Status

Those statuses only work on a path without action in the chain. If so, you have to exec the chain before getting the status.

  • isFile(): boolean: Returns a boolean if the path of the chain is a File.
  • isDirectory(): boolean: Returns a boolean if the path of the chain is a Directory.
  • isSymlink(): boolean: Returns a boolean if the path of the chain is a Symlink.

Dynamic getters

easyPath uses Javascript Proxy to have possibility to write syntax like this:

path('~').foo.bar.bur.bor.toString();
// output ~\foo\bar\bur\bor

Examples

import { path } from "https://deno.land/x/easypath/mod.ts";

path("/")
  .join("foo")
  .join("bar.ts")
  .toString(); // output /foo/bar.ts

path()
  .join("bar.ts")
  .touch()
  .execSync(); // create ./bar.ts Synchronously

const e = path()
  .join("bar.ts")
  .touch();
await e.exec(); // create ./bar.ts Asynchronously

// you can also chain actions
path()
  .join("subFolder")
  .mkdir()
  .join("foo.ts")
  .touch()
  .execSync(); // create ./subFolder/bar.ts Synchronously

const e = path()
  .join("subFolder")
  .mkdir()
  .join("foo.ts")
  .touch();
await e.exec(); // create ./subFolder/bar.ts Asynchronously

path()
  .join("foo.ts")
  .copy({ to: path(testRootPath).join("bar.ts") })
  .execSync();
// Will copy ./foo.ts to ./bar.ts

path()
  .join("foo.ts")
  .copy({ into: path(testRootPath).join("sub") })
  .execSync();
// Will copy ./foo.ts to ./sub/bar.ts

// copy accept also EasyPath chains.
path(testRootPath)
  .join("foo.ts")
  .copy({
    into: path(testRootPath)
      .join("sub")
      .mkdir()
  })
  .execSync();
// Will copy ./foo.ts to ./sub/bar.ts
// Note chains in the copy args are executed synchronously

TODO

  • Add symlink resolution

deno_easypath's People

Contributors

mati-o avatar rehmsen avatar zekth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.