Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

l-utility

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

l-utility - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.npmignore

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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc