定制 jeffersongoncalves/laravel-npm-readme 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jeffersongoncalves/laravel-npm-readme

Composer 安装命令:

composer require jeffersongoncalves/laravel-npm-readme

包简介

A Laravel package that fetches an npm package's README from the registry document, renders the markdown and caches the resulting HTML. The default renderer strips raw HTML; provide your own renderer callable (and sanitize) to keep it. Rendered HTML is untrusted — sanitize it before display.

README 文档

README

Laravel npm Readme

Laravel npm Readme

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Fetch an npm package's README straight from the registry document, render the markdown and cache the resulting HTML. The npm registry ships the README markdown inline in the package document, so there is no extra request beyond the registry call.

This is the npm sibling of jeffersongoncalves/laravel-github-readme.

Installation

composer require jeffersongoncalves/laravel-npm-readme

Optionally publish the config:

php artisan vendor:publish --tag="npm-readme-config"

Usage

use JeffersonGoncalves\NpmReadme\NpmReadme;

$html = NpmReadme::fetchHtml('https://www.npmjs.com/package/laravel-echo');
// or a scoped package:
$html = NpmReadme::fetchHtml('https://www.npmjs.com/package/@tailwindcss/vite');

fetchHtml() returns the rendered HTML, or null when the URL isn't an npm package, the registry has no document, or the package ships no README. Results are cached on the default cache store (npm_readme:{package}) for config('npm-readme.cache_minutes').

NpmReadme::packageFromUrl($url) is also public if you only need the package identifier.

Security

The rendered HTML is untrusted (third-party package READMEs). The default renderer therefore strips raw HTML (html_input = strip), so an embedded <script> cannot become stored XSS.

If you need raw HTML kept, provide your own renderer callable in config/npm-readme.php — the output is then unsafe and you must sanitize it before display, e.g. with jeffersongoncalves/laravel-html-sanitizer:

// config/npm-readme.php
'renderer' => [\App\Support\Markdown::class, 'render'],

Configuration

Key Default Description
cache_minutes 60 Minutes the rendered HTML is cached per package.
registry_url https://registry.npmjs.org npm registry base URL.
timeout 8 Registry request timeout in seconds.
user_agent laravel-npm-readme User-Agent header for the registry request.
renderer null Optional callable(string $markdown): string. When null, an internal CommonMark renderer (GFM + heading permalinks, raw HTML stripped) is used.

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固