Skip to content

Commit

Permalink
Merge pull request #1 from dailyrandomphoto/1.0.0
Browse files Browse the repository at this point in the history
1.0.0
  • Loading branch information
dailyrandomphoto authored Oct 31, 2019
2 parents 9bf4b90 + f8c7488 commit 1f3534a
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 3,005 deletions.
19 changes: 0 additions & 19 deletions .eslintrc.json

This file was deleted.

63 changes: 3 additions & 60 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,61 +1,4 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
package-lock.json
yarn.lock
.nyc_output/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
language: node_js

sudo: false

cache:
apt: true
directories:
- node_modules

node_js:
- "8"
- "10"
- "node"
- "12"
- "13"

script:
- npm run eslint
- npm run lint
- npm run test-cov

after_script:
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# node-serialization

[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-url]
[![LICENSE][license-image]][license-url]
[![Build Status][travis-image]][travis-url]
[![Coverage Status][coveralls-image]][coveralls-url]
Expand Down Expand Up @@ -110,10 +109,10 @@ Copyright (c) 2019 dailyrandomphoto. Licensed under the [MIT license][license-ur
[dependencies-url]: https://david-dm.org/dailyrandomphoto/node-serialization
[devDependencies-url]: https://david-dm.org/dailyrandomphoto/node-serialization?type=dev

[npm-downloads-image]: https://img.shields.io/npm/dm/node-serialization.svg
[npm-version-image]: https://img.shields.io/npm/v/node-serialization.svg
[license-image]: https://img.shields.io/npm/l/node-serialization.svg
[travis-image]: https://img.shields.io/travis/dailyrandomphoto/node-serialization/master
[coveralls-image]: https://coveralls.io/repos/github/dailyrandomphoto/node-serialization/badge.svg?branch=master
[dependencies-image]: https://david-dm.org/dailyrandomphoto/node-serialization/status.svg
[devDependencies-image]: https://david-dm.org/dailyrandomphoto/node-serialization/dev-status.svg
[npm-downloads-image]: https://img.shields.io/npm/dm/node-serialization
[npm-version-image]: https://img.shields.io/npm/v/node-serialization
[license-image]: https://img.shields.io/npm/l/node-serialization
[travis-image]: https://img.shields.io/travis/dailyrandomphoto/node-serialization
[coveralls-image]: https://img.shields.io/coveralls/github/dailyrandomphoto/node-serialization
[dependencies-image]: https://img.shields.io/david/dailyrandomphoto/node-serialization
[devDependencies-image]: https://img.shields.io/david/dev/dailyrandomphoto/node-serialization
12 changes: 6 additions & 6 deletions lib/convert.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const serialization = require('./serialization');

function convert(srcFile, srcDeserialize, destFile, destSerialize) {
const { readFile } = serialization(null, srcDeserialize);
const { writeFile } = serialization(destSerialize, null);
const {readFile} = serialization(null, srcDeserialize);
const {writeFile} = serialization(destSerialize, null);

return readFile(srcFile).then((content) => writeFile(destFile, content));
return readFile(srcFile).then(content => writeFile(destFile, content));
}

function convertSync(srcFile, srcDeserialize, destFile, destSerialize) {
const { readFileSync } = serialization(null, srcDeserialize);
const { writeFileSync } = serialization(destSerialize, null);
const {readFileSync} = serialization(null, srcDeserialize);
const {writeFileSync} = serialization(destSerialize, null);

writeFileSync(destFile, readFileSync(srcFile));
}

module.exports = { convert, convertSync };
module.exports = {convert, convertSync};
10 changes: 5 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const { serialize, deserialize } = require('v8');
const {serialize, deserialize} = require('v8');
const serialization = require('./serialization');
const {
serializeJson,
deserializeJson,
readJson,
writeJson,
readJsonSync,
writeJsonSync,
writeJsonSync
} = require('./json');
const { convert, convertSync } = require('./convert');
const {convert, convertSync} = require('./convert');

const {
readFile,
writeFile,
readFileSync,
writeFileSync,
writeFileSync
} = serialization(serialize, deserialize);

module.exports = {
Expand All @@ -35,5 +35,5 @@ module.exports = {
writeJsonSync,

convert,
convertSync,
convertSync
};
15 changes: 9 additions & 6 deletions lib/json.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
const fs = require('fs-extra');

const serializeJson = (obj) => JSON.stringify(obj);
const serializeJson = obj => JSON.stringify(obj);

const deserializeJson = (str) => JSON.parse(str);
const deserializeJson = str => JSON.parse(str);

const writeJson = (file, contents) => {
let file2 = file;
if (typeof file === 'string') {
file2 = `${file}.writing`;
}

return fs.writeJson(file2, contents)
.then(() => {
if (file2 !== file) {
fs.rename(file2, file, (err) => {
if (err) throw err;
});
return fs.move(file2, file, {overwrite: true})
.catch(error => {
throw error;
});
}
});
};
Expand All @@ -24,6 +26,7 @@ const writeJsonSync = (file, contents) => {
if (typeof file === 'string') {
file2 = `${file}.writing`;
}

fs.writeJsonSync(file2, contents);
if (file2 !== file) {
fs.renameSync(file2, file);
Expand All @@ -36,5 +39,5 @@ module.exports = {
readJson: fs.readJson,
writeJson,
readJsonSync: fs.readJsonSync,
writeJsonSync,
writeJsonSync
};
17 changes: 9 additions & 8 deletions lib/serialization.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
// const { serialize, deserialize } = require('v8');
const fs = require('fs-extra');

function serialization(serialize, deserialize) {
const readFile = (file) => fs.readFile(file).then((data) => deserialize(data));
const readFile = file => fs.readFile(file).then(data => deserialize(data));

const readFileSync = (file) => deserialize(fs.readFileSync(file));
const readFileSync = file => deserialize(fs.readFileSync(file));

const writeFile = (file, contents) => {
let file2 = file;
if (typeof file === 'string') {
file2 = `${file}.writing`;
}

return fs.writeFile(file2, serialize(contents))
.then(() => {
if (file2 !== file) {
fs.rename(file2, file, (err) => {
if (err) throw err;
});
return fs.move(file2, file, {overwrite: true})
.catch(error => {
throw error;
});
}
});
};
Expand All @@ -26,6 +27,7 @@ function serialization(serialize, deserialize) {
if (typeof file === 'string') {
file2 = `${file}.writing`;
}

fs.writeFileSync(file2, serialize(contents));
if (file2 !== file) {
fs.renameSync(file2, file);
Expand All @@ -38,9 +40,8 @@ function serialization(serialize, deserialize) {
readFile,
writeFile,
readFileSync,
writeFileSync,
writeFileSync
};
}


module.exports = serialization;
Loading

0 comments on commit 1f3534a

Please sign in to comment.