file-easy
File utilities to speed up creating document files, setting default extension, and getting a slug
from a string.
Installation
npm i file-easy
Usage
.slug()
const fileEasy = // getting a sluglet fn = 'source Filename';let slug = fileEasyconsole
Will show:
Slug: source-filename
const fileEasy = let names = 'Simple_File$Goes%Here' '%%Welcome** Buddy%&^#$%';names
Will show:
Source: " Simple_File$Goes%Here " is: " simple-file-goes-hereSource: " %%Welcome** Buddy%&^#$% " is: " welcome-buddy
.setDefaultExtension()
const fileEasy = // f1 is filename.js (no extension in original, apply extension)let f1 = fileEasy
.saveDocument()
const fileEasy = let filename = './docs/sample.txt'let content = 'String to go in' /** * Creates the `sample.txt` file in `./docs` folder * If path does not exist, it will create it (e.g. `./docs`) * The file is saved as a utf-8 format (standard format) */fileEasy
Functions
- setDefaultExtension(filename, extension) ⇒
string
Append specified extension if needed.
- saveDocument(filename, content)
Save content in a file using utf8 format.
- slug(s) ⇒
string
Convert a string into an identifier.
string
setDefaultExtension(filename, extension) ⇒ Append specified extension if needed.
Kind: global function
Returns: string
- filename with either existing or specified extension
Param | Type | Description |
---|---|---|
filename | string |
the filename to check for an existing extension. |
extension | string |
the extension to append if filename has no extension. It should start with a dot (e.g. .txt ) |
saveDocument(filename, content)
Save content in a file using utf8 format.
Kind: global function
Param | Type | Description |
---|---|---|
filename | string |
The filename to create. It can also include a path ending with the filename. Path will be created if not exists. |
content | string |
The content to place in the file. |
string
slug(s) ⇒ Convert a string into an identifier.
Kind: global function
Returns: string
- The identifier string
Param | Type | Description |
---|---|---|
s | string |
The string to convert by replacing special characters with dash (-) |