Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 3, 2015
1 parent 27fc228 commit 8b73525
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
[{package.json,*.yml}]
indent_style = space
indent_size = 2

Expand Down
13 changes: 0 additions & 13 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sudo: false
language: node_js
node_js:
- 'iojs'
- 'stable'
- '0.12'
- '0.10'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "http://sindresorhus.com"
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
Expand Down
28 changes: 13 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@

## Install

```sh
```
$ npm install --save temp-write
```


## Usage

```js
var fs = require('fs');
var tempWrite = require('temp-write');
const fs = require('fs');
const tempWrite = require('temp-write');

var filepath = tempWrite.sync('unicorn');
//=> /var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b
const filepath = tempWrite.sync('unicorn');
//=> '/var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b'

fs.readFileSync(filepath, 'utf8');
//=> unicorn
//=> 'unicorn'


tempWrite.sync('unicorn', 'pony.png');
//=> /var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b/pony.png
//=> '/var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b/pony.png'

tempWrite.sync('unicorn', 'rainbow/cake/pony.png');
//=> /var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b/rainbow/cake/pony.png
//=> '/var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b/rainbow/cake/pony.png'
```


Expand All @@ -37,23 +37,21 @@ tempWrite.sync('unicorn', 'rainbow/cake/pony.png');

Returns a promise that resolves to the filepath of the temp file.

### tempWrite.sync(input, [filepath])

Returns the filepath of the temp file.

#### input

*Required*
Type: `string`, `buffer`

#### filepath

Type: `string`
Type: `string`
Example: `'img.png'`, `'foo/bar/baz.png'`

Optionally supply a filepath which is appended to the random path.

### tempWrite.sync(input)

Type: `string`, `buffer`
Returns: the filepath


## Related

Expand Down
12 changes: 6 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import fs from 'fs';
import test from 'ava';
import path from 'path';
import tempWrite from './';
import test from 'ava';
import fn from './';

test('tempWrite(string)', async t => {
const filepath = await tempWrite('unicorn', 'test.png');
const filepath = await fn('unicorn', 'test.png');

t.is(fs.readFileSync(filepath, 'utf8'), 'unicorn');
t.is(path.basename(filepath), 'test.png');
t.end();
});

test('tempWrite(buffer)', async t => {
const filepath = await tempWrite(new Buffer('unicorn'), 'test.png');
const filepath = await fn(new Buffer('unicorn'), 'test.png');

t.is(fs.readFileSync(filepath, 'utf8'), 'unicorn');
t.end();
});

test('tempWrite(string, path)', async t => {
const filepath = await tempWrite(new Buffer('unicorn'), 'foo/bar/test.png');
const filepath = await fn(new Buffer('unicorn'), 'foo/bar/test.png');

t.is(fs.readFileSync(filepath, 'utf8'), 'unicorn');
t.regexTest(/foo\/bar\/test\.png$/, filepath);
t.end();
});

test('tempWrite.sync()', t => {
t.is(fs.readFileSync(tempWrite.sync('unicorn'), 'utf8'), 'unicorn');
t.is(fs.readFileSync(fn.sync('unicorn'), 'utf8'), 'unicorn');
t.end();
});

0 comments on commit 8b73525

Please sign in to comment.