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

yaml-types

v0.4.0

Published

Useful JavaScript types for YAML

Downloads

571,078

Readme

yaml-types

Additional useful types for yaml.

Installation and Usage

npm install yaml yaml-types

Each type (a.k.a. "tag") is available as a named export of 'yaml-types'. These may then be used as custom tags:

import { parse } from 'yaml'
import { regexp } from 'yaml-types'

const re = parse('!re /fo./g', { customTags: [regexp] })
'foxbarfoo'.match(re) // [ 'fox', 'foo' ]

Available Types

  • bigint (!bigint) - JavaScript BigInt values. Note: in order to use this effectively, a function must be provided as customTags in order to prepend the bigint tag, or else the built-in !!int tags will take priority. See bigint.test.ts for examples.
  • binary (!!binary) - JavaScript Uint8Array, one of the YAML 1.1 tags
  • classTag (!class) - JavaScript Class values
  • error (!error) - JavaScript Error objects
  • functionTag (!function) - JavaScript Function values (will also be used to stringify Class values, unless the classTag tag is loaded ahead of functionTag)
  • nullobject (!nullobject) - Object with a null prototype
  • omap (!!omap) - JavaScript Map, one of the YAML 1.1 tags
  • pairs (!!pairs) - Ordered sequence of key-value pairs, one of the YAML 1.1 tags
  • regexp (!re) - RegExp values, using their default /foo/flags string representation.
  • set (!!set) - JavaScript Set, one of the YAML 1.1 tags
  • sharedSymbol (!symbol/shared) - Shared Symbols, i.e. ones created with Symbol.for()
  • symbol (!symbol) - Unique Symbols
  • timestamp (!!timestamp) - JavaScript Date, one of the YAML 1.1 tags

The function and class values created by parsing !function and !class tags will not actually replicate running code, but rather no-op function/class values with matching name and toString properties.

Customising Tag Names

To use one of the types with a different tag identifier, set its tag value accordingly. For example, to extend the default tag namespace with !!js/symbol instead of using a local !symbol tag for Symbol values:

import { stringify } from 'yaml'
import { symbol } from 'yaml-types'

const mysymbol = { ...symbol, tag: 'tag:yaml.org,2002:js/symbol' }
stringify(Symbol('foo'), { customTags: [mysymbol] })
!!js/symbol foo

To use a named tag handle like !js!symbol, a few more steps are required:

import { Document } from 'yaml'
import { symbol } from 'yaml-types'

const mysymbol = { ...symbol, tag: 'tag:js:symbol' }
const doc = new Document(Symbol('foo'), { customTags: [mysymbol] })
doc.directives.tags['!js!'] = 'tag:js:'
doc.toString()
%TAG !js! tag:js:
---
!js!symbol foo

Contributing

Additions to this library are very welcome! Many data types are useful beyond any single project, and while the core yaml library is mostly limited to the YAML spec, no such restriction applies here.

The source code is written in TypeScript, and the tests use Node-Tap. When submitting a PR for a new type, tests and documentation are required, as well as satisfying Prettier.