Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/saintedlama/replace-shebang

Replaces the shebang by some string or nothing
https://github.com/saintedlama/replace-shebang

regex shebang

Last synced: about 2 months ago
JSON representation

Replaces the shebang by some string or nothing

Awesome Lists containing this project

README

        

# replace-shebang [![Build Status](https://travis-ci.org/saintedlama/replace-shebang.svg?branch=master)](https://travis-ci.org/saintedlama/replace-shebang)

> Replaces a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) *(eg. `#!/bin/sh`)* by a string using string.replace

## Install

```
$ npm install --save replace-shebang
```

## Usage

```js
const fs = require('fs');
const replaceShebang = require('replace-shebang');

const str = fs.readFileSync('bin', 'utf8');
//=> #!/usr/bin/env node
//=> console.log('unicorns');

// string replacement
replaceShebang(str, '// shebang');
//=> // shebang
//=> console.log('unicorns');

// function to replace the shebang
replaceShebang(str, shebang => '// ' + shebang);
//=> // #!/usr/bin/env node
//=> console.log('unicorns');

// stripping shebangs
replaceShebang(str);
//=>
//=> console.log('unicorns');
```