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

md.daily

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

md.daily - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

src/Daily.js

3

package.json
{
"name": "md.daily",
"version": "1.0.2",
"version": "2.0.0",
"description": "for daily store",

@@ -26,2 +26,3 @@ "main": "src/index.js",

"chokidar": "^2.0.3",
"glob": "^7.1.2",
"md5": "^2.2.1",

@@ -28,0 +29,0 @@ "then-fs": "^2.0.0"

@@ -1,81 +0,3 @@

const path = require('path')
, fs = require('then-fs')
, parse = require('./parse')
, chokidar = require('chokidar')
, MetaProxy = require('./MetaProxy')
class Daily extends MetaProxy {
/**
* @description Daily constructor
* @param { String } file_path 文件绝对路径
*/
constructor(file_path) {
super();
// 参数初始化
this.file_path = file_path;
this.data = null;
}
/**
* @description 带缓存的 getData
* @returns { Promise<Daily> }
*/
getData() {
if (this.data) {
return Promise.resolve(this);
} else {
return this.read().then(data => {
data.file_path = this.file_path;
this.data = data;
return this;
});
}
}
/**
* @description 从磁盘中读取 file_path 返回 Promise
* @returns { Promise<Object> } 文章经过 parse 的结果
*/
read() {
return fs.readFile(this.file_path)
.then(e => e.toString())
.then(parse)
}
/**
* @description watch
* @returns { Daily } 链式调用
*/
beginWatch() {
if (this.watcher) return this;
// 绑定 watcher
this.watcher = chokidar.watch(this.file_path);
// !!! 热更新
this.watcher.on('change', path => {
this.data = null;
this.emit('change', this);
});
// 当文件被删除
// 被动的取消绑定
this.watcher.on('unlink', path => {
this.endWatch();
});
return this;
}
/**
* @description 主动取消绑定
* @returns { Daily } 链式调用
*/
endWatch() {
this.watcher.close();
this.watcher = null;
return this;
}
module.exports = {
Daily: require('./Daily')
}
module.exports = Daily;
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