Giter VIP home page Giter VIP logo

file-easy's Introduction

file-easy

File utilities to speed up creating document files, setting default extension, and getting a slug from a string.

DeepScan grade

Installation

npm i file-easy

Usage

.slug()

const fileEasy = require('file-easy')

// getting a slug
let fn = 'source Filename';
let slug = fileEasy.slug(fn)
console.log('Slug:', slug)

Will show:

Slug: source-filename
const fileEasy = require('file-easy')

let names = [
    'Simple_File$Goes%Here',
    '%%Welcome**    Buddy%&^#$%'
];
names.forEach((name) => {
    console.log('Source: "', name, '" is:', fileEasy.slug(name))
})

Will show:

Source: " Simple_File$Goes%Here " is: " simple-file-goes-here
Source: " %%Welcome**    Buddy%&^#$% " is: " welcome-buddy

.setDefaultExtension()

const fileEasy = require('file-easy')

// f1 is filename.js (no extension in original, apply extension)
let f1 = fileEasy.setDefaultExtension('filename', '.js)

// f2 is filename.js (extension already exists)
let f2 = fileEasy.setDefaultExtension('filename.js', '.json')

// f3 is filename. (extension starts with . in original)
let f3 = fileEasy.setDefaultExtension('filename.', '.js')

.saveDocument()

const fileEasy = require('file-easy')

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.saveDocument(filename, content)

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.

setDefaultExtension(filename, extension) ⇒ string

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.

slug(s) ⇒ string

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 (-)

file-easy's People

Contributors

ioncakephper 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.