front-matter vs gray-matter vs yaml-front-matter
フロントマターライブラリ
front-mattergray-matteryaml-front-matter類似パッケージ:
フロントマターライブラリ

フロントマターライブラリは、Markdownファイルのメタデータを解析し、管理するためのツールです。これらのライブラリは、Markdownコンテンツの前に配置されたYAML形式のメタデータを簡単に処理し、データを取得するための便利な機能を提供します。これにより、ブログやドキュメント生成ツールなどで、コンテンツの管理が容易になります。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
front-matter3,908,724689-326年前MIT
gray-matter2,581,7184,303-685年前MIT
yaml-front-matter74,566194-215年前MIT
機能比較: front-matter vs gray-matter vs yaml-front-matter

データ形式のサポート

  • front-matter:

    front-matterは、主にYAML形式のメタデータをサポートしています。シンプルな構文で、Markdownファイルの先頭に配置するだけで、メタデータを簡単に追加できます。

  • gray-matter:

    gray-matterは、YAMLとJSONの両方の形式をサポートしており、開発者は好みの形式を選択できます。これにより、柔軟なデータ管理が可能です。

  • yaml-front-matter:

    yaml-front-matterは、YAML形式に特化しており、YAMLの特性を活かした高度な解析機能を提供します。YAMLの構文に慣れているユーザーにとって、非常に使いやすいです。

使いやすさ

  • front-matter:

    front-matterは、非常にシンプルで直感的なAPIを提供しており、初心者でも簡単に使用できます。基本的な機能に特化しているため、学習曲線が緩やかです。

  • gray-matter:

    gray-matterは、機能が豊富であるため、少し学習が必要ですが、ドキュメントが充実しており、使いこなすことで多くの利点を享受できます。

  • yaml-front-matter:

    yaml-front-matterは、YAMLの特性を活かした設計になっているため、YAMLに慣れているユーザーにとっては非常に使いやすいですが、YAMLに不慣れなユーザーには少し難しいかもしれません。

パフォーマンス

  • front-matter:

    front-matterは、軽量なライブラリであり、パフォーマンスに優れています。大規模なデータセットを扱う場合でも、迅速にメタデータを解析できます。

  • gray-matter:

    gray-matterは、柔軟性が高い分、少しオーバーヘッドがあるかもしれませんが、適切に使用すれば、十分なパフォーマンスを発揮します。

  • yaml-front-matter:

    yaml-front-matterは、YAMLの解析に特化しているため、YAMLデータの処理において高いパフォーマンスを発揮しますが、他の形式には対応していないため、用途によっては制限があります。

拡張性

  • front-matter:

    front-matterは、シンプルな設計のため、拡張性は限られていますが、基本的なニーズには十分に対応しています。

  • gray-matter:

    gray-matterは、プラグインやカスタムパーサーを追加することで、機能を拡張することができ、さまざまなプロジェクトに対応可能です。

  • yaml-front-matter:

    yaml-front-matterは、YAMLに特化しているため、YAMLの特性を活かした拡張が可能ですが、他の形式との互換性はありません。

メンテナンス

  • front-matter:

    front-matterは、シンプルな構造のため、メンテナンスが容易です。バグ修正や機能追加が迅速に行われます。

  • gray-matter:

    gray-matterは、活発なコミュニティがあり、定期的に更新されているため、メンテナンス状況は良好です。

  • yaml-front-matter:

    yaml-front-matterは、特定のニーズに特化しているため、メンテナンスは行われていますが、他のライブラリに比べて更新頻度は低いかもしれません。

選び方: front-matter vs gray-matter vs yaml-front-matter
  • front-matter:

    シンプルなメタデータの解析が必要な場合は、front-matterを選択してください。このライブラリは、基本的な機能を提供し、軽量で使いやすいです。

  • gray-matter:

    より多機能で、YAMLとJSONの両方をサポートする必要がある場合は、gray-matterを選択してください。このライブラリは、柔軟性が高く、さまざまなデータ形式に対応しています。

  • yaml-front-matter:

    YAML形式のメタデータを特に重視する場合は、yaml-front-matterを選択してください。このライブラリは、YAMLの解析に特化しており、YAMLの特性を最大限に活かすことができます。

front-matter のREADME

front-matter

build coverage npm github

Sauce Test Status

Extract meta data (front-matter) from documents.

This modules does not do any IO (file loading or reading), only extracting and parsing front matter from strings.

This concept that was originally introduced to me through the jekyll blogging system and is pretty useful where you want to be able to easily add meta-data to content without the need for a database. YAML is extracted from the the top of a file between matching separators of "---" or "= yaml =". It will also extract YAML between a separator and "...".

Install

With npm do:

npm install front-matter

Example

So you have a file example.md:

---
title: Just hack'n
description: Nothing to see here
---

This is some text about some stuff that happened sometime ago

NOTE: As of front-matter@2.0.0 valid front matter is considered to have the starting separator on the first line.

Then you can do this:

var fs = require('fs')
  , fm = require('front-matter')

fs.readFile('./example.md', 'utf8', function(err, data){
  if (err) throw err

  var content = fm(data)

  console.log(content)
})

And end up with an object like this:

{
    attributes: {
        title: 'Just hack\'n',
        description: 'Nothing to see here'
    },
    body: 'This is some text about some stuff that happened sometime ago',
    bodyBegin: 6,
    frontmatter: 'title: Just hack\'n\ndescription: Nothing to see here'
}

Methods

var fm = require('front-matter')

fm(string, { allowUnsafe: false })

Return a content object with two properties:

  • content.attributes contains the extracted yaml attributes in json form
  • content.body contains the string contents below the yaml separators
  • content.bodyBegin contains the line number the body contents begins at
  • content.frontmatter contains the original yaml string contents

NOTE: By default fm() uses ys-yaml's safeLoad unless you set allowUnsafe in the options object to true.

fm.test(string)

Check if a string contains a front matter header of "---" or "= yaml =". Primarily used internally but is useful outside of the module.

Returns true or false

    fm.test(string) #=> true || false

Contributing

front-matter is an OPEN Source Project so please help out by reporting bugs or forking and opening pull requests when possible.

standard

All code is linted/formatted using standard style, any non-conforming code can be automatically formatted using the the fmt make task: make fmt.

Maintainers

Contributors

This module is awesome because of all the folks who submitted pull requests:

CHANGELOG

3.0.0

  • CI only tests Node versions >= v6 (drops v4, and v5)

LICENSE (MIT)

Copyright (c) Jason Campbell ("Author")

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.