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

better-concat

v1.0.1

Published

concatenate multiple files

Downloads

1

Readme

Better Concat

Concatenate multiple files and folders

Install

$ npm install better-concat
import concat from 'better-concat'

Usage

The most simple use

await concat({
    files: ['file1.js', 'file2.js', ...],
    out: 'out.js',
})

Concat files and folders

You can pass folders in the files array and those folders will be scanned and all the contained files will be merged respecting the order.

await concat({
    files: ['file1.js', 'folder1', 'folder2', 'file2.js', ...],
    out: 'out.js',
})

Exclude certain files

If you pass folders in the files list you can use the exclude option to decide wich files are excluded. Exclude can be an array of the files to ignore or a function

// List example
await concat({
    files: ['file1.js', 'folder1', 'folder2', 'file2.js', ...],
    exclude: ['package.json'],
    out: 'out.js',
})

// Function example
await concat({
    files: ['file1.js', 'folder1', 'folder2', 'file2.js', ...],
    exclude: (file, path) => {
        if (file == 'package.json') {
            return true; //exclude this file
        }
        return false;
    },
    out: 'out.js',
})

Manipulate individual files strings before merge

You can manipulate individual file strings before the string is merged

await concat({
    files: ['file1.js', 'folder1', 'folder2', 'file2.js', ...],
    fileStr: (str, path) => {
        if (path.endsWith('package.json')) {
            return str.replace('word', '');
        }
        return str;
    },
    out: 'out.js',
})

Manipulate the complete merged string before it's saved

You can manipulate the merged string with a function.

await concat({
    files: ['file1.js', 'folder1', 'folder2', 'file2.js', ...],
    outStr: (str) => {
        return str.replace('word', '');
    },
    out: 'out.js',
})

Prepend and append to the output string

You can prepend or append anything to the merged string

await concat({
    files: ['file1.js', 'folder1', 'folder2', 'file2.js', ...],
    prepend: '(function () {\n"use strict";\n\n',
    append: '})();',
    out: 'out.js',
})

Return the merged string

Instead of saving the merged string in a file you can save it in a variable and do whatever you want

const concateStr = await concat({
    files: ['file1.js', 'folder1', 'folder2', 'file2.js', ...],
    out: false,
})

All available options

const concateStr = await concat({
    files: ['file1.js', 'folder1', ...],
    out: 'path to save the merged file or false',
    exclude: 'list of files to exclude or function',
    invisibles: 'include invisible files if passed folders in files list (false by default)',
    outStr: 'function to manipulate the string before it\'s saved or returned',
    fileStr: 'function to manipulate the string of individual files',
    prepend: 'prepend string to the merged file',
    append: 'append string to the merged file',
    delimiter: 'delimiter used to merge the files, default is \n leave empty to remove all line breaks'
})

If you like this

:star: this repo

License

MIT

Copyright (c) 2019 biati digital