1.0.18 ā€¢ Published 10 days ago

path-minifier v1.0.18

Weekly downloads
-
License
MIT
Repository
github
Last release
10 days ago

path-minifier

šŸ”„ Minify the path list while preserving semantics

Demo

This is a utility to reduce the number of characters in a path listing while maintaining the semantics of the directory structure and file names. It was created primarily to reduce the number of tokens used when passing directory information to LLM (e.g. ChatGPT, GPT-4).

Installation

npm i path-minifier

Example

Returns a string list of paths with reduced size by passing the list of paths as a string[].

import { minify } from 'path-minifier'

const minified = minify([
  'README.md',
  'package.json',
  'src/index.js',
  'src/lib.js'
  // ...
])

By default, the output automatically selects the format with the least number of characters. This behavior can be overridden with the options argument.

const minified = minify(
  [
    // ...
  ],
  {
    /** 'object' | 'json' | 'indented-list' | 'auto'(default) */
    format: 'json'
  }
)

Output Formats

object

Output as a JS object. Single files are output as strings, multiple files as arrays, and directories as objects. Can be used to convert to any string format using JSON.stringify or similar.

const obj = [
  'README.md',
  'package.json',
  {
    src: ['index.js', '...']
  }
]

json

Outputs object as an unformatted JSON string. The larger the size of the directory, the more characters it tends to reduce.

["README.md", "package.json", { "src": ["index.js", "..."] }]

indented-list

Output as indented-list Outputs the directory structure as a list of indented filenames without escaping. Provides smaller output size for small directories and irregular nested structures. Indentation is done with \t.

README.md
package.json
src
  index.js
  ...

auto

Automatically selects the output with the fewest number of haracters and returns the value as a string.

!IMPORTANT The auto option selects the output format based on the length of the string, which may not be proportional to the length of the LLM token. See the interactive demo for a description of this behavior.

License

MIT

1.0.18

10 days ago

1.0.17

20 days ago

1.0.16

23 days ago

1.0.15

28 days ago

1.0.14

1 month ago

1.0.13

1 month ago

1.0.12

1 month ago

1.0.11

2 months ago

1.0.10

2 months ago

1.0.9

2 months ago

1.0.8

3 months ago

1.0.7

3 months ago

1.0.6

3 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

5 months ago

1.0.0

5 months ago

0.0.1

6 months ago