npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-computed

v0.9.3

Published

文件型计算属性,当且仅当文件变化时才重新做计算

Downloads

143

Readme

动机

有时候我们的计算在特定目标文件不变时结果是一样的,当计算特别耗时复杂时可以通过本地文件缓存的方式快速得到原先的结果,而不需要每一次都进行该计算,以此提高运算效率。

使用

安装

pnpm i file-computed

基础

import { createFsComputed } from 'file-computed'

const fsComputed = createFsComputed()

const result = await fsComputed('package.json', () => {
	/** 模拟复杂计算,只会跑一次,后边会直接获取缓存中的结果 */
	let n = 0
	let t = 10000
	while (t--) {
		n++
	}
	return n
})

result // 10000

缓存路径

import { createFsComputed } from 'file-computed'

const fsComputed = createFsComputed({
	cachePath: 'temp' // 默认为最近 node_modules 的 .cache/.file-computed
})

同步

import { createFsComputedSync } from 'file-computed'

const fsComputed = createFsComputedSync()

const result = fsComputed('package.json', () => {
	/** 模拟复杂计算,只会跑一次,后边会直接获取缓存中的结果 */
	let n = 0
	let t = 10000
	while (t--) {
		n++
	}
	return n
})

result // 10000

适合大型缓存

import { createFsComputedWithStream } from 'file-computed'

const fsComputed = createFsComputedWithStream()

const result = await fsComputed('package.json', () => {
	/** 模拟复杂计算,只会跑一次,后边会直接获取缓存中的结果 */
	let n = 0
	let t = 10000
	while (t--) {
		n++
	}
	return n
})

result // 10000

后置写

开启 post,结果将优先返回,速度更快

import { createFsComputedWithStream } from 'file-computed'

const fsComputed = createFsComputedWithStream({
	post: true
})

const result = await fsComputed('package.json', () => {
	let n = 0
	let t = 10000
	while (t--) {
		n++
	}
	return n
})

result // 写被后置了,结果 10000 优先返回

因为写被后置了,所以下次计算前,缓存与否是不确定的

License

Made with markthree

Published under MIT License.