Comparing version 1.0.0 to 1.0.1
38
index.js
const fs = require('fs'); | ||
const path = require('path'); | ||
const crypto = require('crypto'); | ||
const moment = require('moment'); | ||
@@ -8,14 +8,14 @@ const mongodb = require('mongodb'); | ||
class Utils { | ||
md5(content = '') { | ||
md5 (content = '') { | ||
return crypto.createHash('md5').update(content).digest('hex'); | ||
} | ||
sha256(content = '') { | ||
sha256 (content = '') { | ||
return crypto.createHash('sha256').update(content).digest('hex'); | ||
} | ||
newObjectId(id) { | ||
newObjectId (id) { | ||
try { | ||
return new mongodb.ObjectId(id); | ||
} catch(err) { | ||
} catch (error) { | ||
throw new Error('the id length must be 24'); | ||
@@ -25,3 +25,3 @@ } | ||
objectIdToDate(id) { | ||
objectIdToDate (id) { | ||
if (!id || typeof id !== 'string' || id.length !== 24) throw Error('无效的ID'); | ||
@@ -31,12 +31,7 @@ return this.newObjectId(id).getTimestamp(); | ||
dateToObjectId(date) { | ||
return this.newObjectId(`${moment(date).unix().toString(16)}`.padEnd(24, 0)) | ||
dateToObjectId (date) { | ||
return this.newObjectId(`${moment(date).unix().toString(16)}`.padEnd(24, 0)); | ||
} | ||
residue(count, limit) { | ||
limit = limit || 20; | ||
return Math.max(count - limit, 0); | ||
} | ||
getDomain(host) { | ||
getDomain (host) { | ||
const localhost = 'localhost'; | ||
@@ -47,16 +42,9 @@ // host可能存在的值:localhost、51linwei.top、51linwei.top:3451 | ||
downloadFile(url, name) { | ||
const stream = fs.createWriteStream(name); | ||
request(url).pipe(stream).on('close', function() { | ||
console.log('下载完成'); | ||
}); | ||
} | ||
downloadFile (url, name) { request(url).pipe(fs.createWriteStream(name)).on('close', () => { console.log('下载完成'); }); } | ||
asdf(source) { | ||
const type = source.substr(source.lastIndexOf('.') + 1, source.length); | ||
return { type, result: fs.createReadStream(source) }; | ||
} | ||
loadFile (source) { return { type: source.substr(source.lastIndexOf('.') + 1, source.length), result: fs.createReadStream(source) }; } | ||
async sleep (ms) { return new Promise(resolve => setTimeout(resolve, ms)); } | ||
} | ||
module.exports = new Utils(); | ||
{ | ||
"name": "l-utility", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "utils for myself", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
20391
5
483
1
53
1