Skip to content

Commit

Permalink
Cleaning up old repos. Updating to ES6 syntax. Updating testing to wo…
Browse files Browse the repository at this point in the history
…rk with node 10 to 13
  • Loading branch information
Michael Collins committed Jan 28, 2020
1 parent aee3403 commit 60bee2c
Show file tree
Hide file tree
Showing 9 changed files with 1,828 additions and 1,686 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -45,7 +45,7 @@
"no-new-wrappers": "error",
"no-octal": "warn",
"no-octal-escape": "warn",
"no-param-reassign": "warn",
"no-param-reassign": "off",
"no-process-env": "off",
"no-proto": "error",
"no-redeclare": "error",
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,8 +1,8 @@
language: node_js
node_js:
- "8.0"
- "10.0"
- "11.0"
- "12.0"
- "13"
sudo: false
script:
- npm test
2 changes: 1 addition & 1 deletion LICENSE.md
@@ -1,7 +1,7 @@
The MIT License (MIT)
=====================

Copyright (c) 2015-2016 Michael Glen Collins
Copyright (c) 2015-2020 Michael Glen Collins

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
48 changes: 9 additions & 39 deletions UPDATE_HISTORY.md
@@ -1,42 +1,12 @@
Update History
==============

### 2.0.1 - 2019-01-02

* Minor bug fix to allow no arguments to be passed into the `hash()` function.
* Fixed ISSUE#5. No longer crash if atime, mtime or ctime don't exist.

---

### 2.0.0

* This is really PR#7 from dwighthouse - But going a little further in updating ALL dependencies and removing code that is no longer needed.
* Fixed ISSUE#6. Directly related to PR#7.

---

### 1.2.0

* PR#3 from tuck182 - Handle generated files that do not support the `file.stat` object.

---

### 1.1.1

* Adding support for coveralls

---

### 1.1.0

* Added code to allow length limitation for any field. {hash} will use the full length while {hash:8} will only use the first 8 characters of the hash value.
* Broke single file into multiple files for testing
* Added Mocha/Chai testing for all non-gulp functionality

---
### 1.0.0


* Initial Release
* Added {name}, {ext}, {hash}, {atime}, {ctime} and {mtime} as options to the format routine
* Set default of format string to "{name}-{hash}{ext}"
| Version | Released | Details |
| --- | --- | --- |
| 3.0.0 | 2020-01-28 | * Updated all 3rd party repos<br/>* Removed node 8 support<br/>* Updated to newer ES6 syntax |
| 2.0.1 | 2019-01-02 | * Minor bug fix to allow no arguments to be passed into the `hash()` function.<br/>* Fixed ISSUE#5. No longer crash if atime, mtime or ctime don't exist. |
| 2.0.0 | | * This is really PR#7 from dwighthouse - But going a little further in updating ALL dependencies and removing code that is no longer needed.<br/>* Fixed ISSUE#6. Directly related to PR#7. |
| 1.2.0 | | * PR#3 from tuck182 - Handle generated files that do not support the `file.stat` object. |
| 1.1.1 | | * Adding support for coveralls |
| 1.1.0 | | * Added code to allow length limitation for any field. {hash} will use the full length while {hash:8} will only use the first 8 characters of the hash value.<br/>* Broke single file into multiple files for testing<br/>* Added Mocha/Chai testing for all non-gulp functionality |
| 1.0.0 | | * Initial Release<br/>* Added {name}, {ext}, {hash}, {atime}, {ctime} and {mtime} as options to the format routine<br/>* Set default of format string to "{name}-{hash}{ext}" |
33 changes: 15 additions & 18 deletions lib/formatStr.js
@@ -1,24 +1,21 @@
var reObj = /\{[^}]+\}/gm;
var reNum = /\{\d+\}/gm;
function formatStr(text, params) {
var re;
function formatStr(text, ...params) {
let re = /\{(([^}]+)|(\d+))\}/gm;

if (arguments.length > 1) {
if(typeof params !== 'object') {
params = Array.prototype.slice.call(arguments, 1); // eslint-disable-line no-param-reassign
re = reNum;
}
else {
re = reObj;
if (params.length > 0) {
if(params.length === 1 && typeof params[0] === 'object') {
params = params[0];
//re = reObj;
} else {
//re = reNum;
}

text = text.replace(re, function(item) { // eslint-disable-line no-param-reassign
var temp = item.slice(1,-1).split(':');
var key = temp[0];
var length = temp[1];
if(params[key] !== undefined) {
temp = params[key];
if (!isNaN(length) && length > 0) {
text = text.replace(re, item => {
const [key, length = 0] = item.slice(1,-1).trim().split(':');

let temp = params[key];

if(temp != null) {
if (length > 0) {
temp = temp.substr(0,length);
}
return temp;
Expand Down
4 changes: 2 additions & 2 deletions lib/generateHash.js
@@ -1,7 +1,7 @@
var crypto = require('crypto');
const crypto = require('crypto');

function generateHash(content){
var hash = crypto.createHash('md5');
const hash = crypto.createHash('md5');
hash.update(content);
return hash.digest('hex');
}
Expand Down
18 changes: 9 additions & 9 deletions lib/performHash.js
@@ -1,13 +1,13 @@
var path = require('path');
var formatStr = require('./formatStr');
var getDateStr = require('./getDateStr');
var generateHash = require('./generateHash');
const path = require('path');
const formatStr = require('./formatStr');
const getDateStr = require('./getDateStr');
const generateHash = require('./generateHash');

function performHash(format, file) {
var ext = path.extname(file.path);
var fname = path.basename(file.path, ext);
var dir = path.dirname(file.path);
var params = {
const ext = path.extname(file.path);
const fname = path.basename(file.path, ext);
const dir = path.dirname(file.path);
const params = {
"name": fname,
"ext": ext,
"hash": generateHash(file.contents),
Expand All @@ -16,7 +16,7 @@ function performHash(format, file) {
"ctime": file.stat && file.stat.ctime ? getDateStr(file.stat.ctime) : '',
"mtime": file.stat && file.stat.mtime ? getDateStr(file.stat.mtime) : ''
};
var fileName = formatStr(format, params);
const fileName = formatStr(format, params);
file.path = path.join(dir, fileName);
return file;
}
Expand Down

0 comments on commit 60bee2c

Please sign in to comment.