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

test262-parser

v2.2.0

Published

Parse a test262-format test and provide API

Downloads

1,617

Readme

Parse test262 test files

This package will allow you to parse test262 test files into their component pieces, for further use and manipulation.

API

parseFile

The simplest function exported by this module is parseFile, which expects either a string representing the file contents, or an object with members file and contents, which are strings containing the filename and contents respectively.

The result of parseFile is an object f with (at least) a contents member.

If the input to parseFile contains the special YAML frontmatter comments /*--- ---*/, then the following things are done:

  1. the copyright message is stored in f.copyright
  2. the YAML frontmatter is parsed and stored as an object, f.attrs
  3. the test's async status (true/false) is stored in f.async
  4. f.contents is modified to contain only the text following the YAML closer comment ---*/

If the input does not contain YAML frontmatter, some of the above parsing is still attempted but the f.contents member will remain unchanged. This provides backwards compatibility to test262-runner which uses parseFile to parse test helpers as well as test files.

parseFile examples

'use strict';
var fs = require('fs');
var test262Parser = require('test262-parser');

var rawTest = fs.readFileSync('built-ins/Array/prototype/includes/array-like.js');

// Pass in file object and it will be mutated with parsed data:
var file = {
    file: 'built-ins/Array/prototype/includes/array-like.js',
    contents: rawTest
};

test262Parser.parseFile(file);
// `file` now has `attrs`, `async`, and `copyright` properties, with `contents` modified

console.log(file.attrs);
// Outputs normalized attributes from the YAML front-matter:
// https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#frontmatter

console.log(file.async);
// Outputs `true` or `false` depending on whether the test is async:
// https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#writing-asynchronous-tests

console.log(file.copyright);
// Outputs the copyright header:
// https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#copyright

console.log(file.contents);
// Outputs the main test body, without the copyright or YAML front-matter.

// You can also parse test contents directly; it will create a file object
var parsedFile = test262Parser.parseFile(rawTest);

console.log(parsedFile.file);      // '<unknown>'
console.log(parsedFile.contents);  // the main test body
console.log(parsedFile.copyright); // the copyright header
console.log(parsedFile.attrs);     // the normalized attributes
consoel.log(parsedFile.async);     // whether or not the test is async

extractYAML

The extractYAML function takes a string containing the text contents and returns back the substring that constitutes the YAML front matter:

'use strict';
var fs = require('fs');
var test262Parser = require('test262-parser');

var testContents = fs.readFileSync('built-ins/Array/prototype/includes/array-like.js');

var yaml = test262Parser.extractYAML(testContents);
console.log(yaml);

will output

description: Array.prototype.includes works on array-like objects
author: Domenic Denicola

Streaming interface

The default export of the module is a transform stream factory. Every time you write a string or file object to the transform stream, it emits a parsed file object:

'use strict';
var fs = require('fs');
var test262Parser = require('test262-parser');

var transformStream = test262Parser();
transformStream.pipe(process.stdout);

var testContents = fs.readFileSync('built-ins/Array/prototype/includes/array-like.js');
transformStream.write(testContents);

will output to process.stdout the (stringification of the) file object.