npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rx-file

v3.1.1

Published

File tree to path

Downloads

3

Readme

npm npm bundle size NPM NPM

Introduction

rx-file is a quick template file creation tool that solves the problem of creating a large number of files manually.

Download

yarn add --dev rx-file

Main Function

Using the tree name to obtain a file tree and convert it into a file path (generate files) is very suitable for creating a large number of template files and deep nesting directories

Quick Use

const treeToFilePath = require('../lib/index')

// The passed parameter can be a relative path to the file (store the copy file tree) or a file tree
const rxFileResult = treeToFilePath('./template.txt')
// const rxFileResult = treeToFilePath(template)


// ./template.txt
const templateTxt = `
home/user
├── foo.js
├── test
|  ├── bar.js
|  └── baz.js
└── bat.js
`
const {generateFile} = rxFileResult

// create file
generateFile()

Tutorial

treeToFilePath returns two properties and a method to create the file. Most of the time, the method generateFile is called to create the file without using the properties

const rxFileResult = treeToFilePath('./template.txt')
const {fileMap, filePath, generateFile} = rxFileResult 
  • fileMap: Map<string, Node>: Returns a file - level structure
  • filePath: string[] : This property stores the relative path of each file
  • generateFile: (root?: string, ops?: FileOptions) => Function; : To create a file
    • root: The root argument is not required you can ignore it and it will create a name of its own which is something like 'themplate-xxxxxxxx' you can specify that it is a file name or a relative path or even an absolute path and when you specify an absolute path you need to specify the third argument as{rootdir: 'none'};
    • ops: What rules are used to determine the template files to be generated
const ops = {
  rootdir: 'none'
}

generateFile(root, ops)
/**
 * root:  Relative path|  Absolute path (The third argument of the function must be passed in when used{rootdir: 'none'})
 * 
 * ops:  { rootdir: '__dirname' | 'tmpdir' | 'none' }
 * 
 * ops.rootdir:
 *   "__dirname" : The default option is used to build under the current folder
 *   "tmpdir"    : Generated in os.tmpdir
 *   "none"      : The whole argument indicates that your root argument is an absolute path
 */

Advanced Settings

You usually don't need to configure this option, but the format of the file tree generated under different commands varies greatly, providing you with an optional operation for precise matching

The configuration item 'defaultOptions' is very necessary. It's the foundation and the core of the rules for dealing with file tree templates. Most of the time you don't need this when your template file doesn't match the default and you need to use it.

const defaultOptions = {
  nullFlie: "NULLFILE",
  Dir: "DIR",
  File: "FILE",
  depth: 5,
  pathSeparator: "/",
  throughTee: "├──",
  endTee: "└──",
  vertical: "|",
};

Configurable

depth : File iteration depth is ignored when your folder is deeper than this

pathSeparator: The symbol 'pathSeparator: "/"' is used to delimit the path of a file when it is processed. This property is generally not configured. By default it is' \ 'in Windows and'/' in linux

throughTee: The symbol 'throughTee: "└──"' for the file (directory) is in one of these

endTee: The last node symbol 'endTee: "temperature ─"' means that the file (directory) is the last one of the parent

vertical: Sun file symbol vertical: "|" file or directory has one or more before, determine its level

Pay attention

Not recommended If you change these, you are likely to get the wrong message

nullFlie: The root node replaces the root node name if it is not available

Dir: Tag directory node

File: Mark file node

For example:

{
  endTee: '|' 
}

// Use
const treeToFilePath = require('rx-file')
treeToFilePath('./xxx.txt', {endTee: '|'})

Override the default properties in this way

Usually the most important throughTee, endTee and vertical that you use, you just need to make sure that these three are correct when you're using them.

Warning⚠

Before using it you must make sure that the default symbols and your template styles match 'rx-file' modules are matched in a regular way it is not particularly smart and you must follow the rules accordingly

  1. If it is the last file or the last directory you must use the symbol "pheo --" or you can specify the symbol '{endTee: "symbol for the last file or directory "}'

  2. You need to choose the appropriate file tree format

A file tree it is in the form of this' └─ 'used to represent the child node' └─ 'used to represent the last file or directory' # 'You can add comments after the whole symbol

home/user
├── foo.js
├── test
|  ├── bar.js # this is comment
|  └── baz.js
└── bat.js
  1. The directory name is not allowed to contain '.js' or '.css 'related characters. When there are'. 'characters, it is considered as a file

  2. Try to name the directory properly otherwise you may see the path to it but the file creation may fail or the file name may not be what you expected

  3. If you ignore the above two points you will get the opposite of what you expect.