Skip to content

Commit

Permalink
Internally, export members directly from src/index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Oct 5, 2020
1 parent 9805351 commit eb8f0d3
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 32 deletions.
2 changes: 1 addition & 1 deletion browser/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist').YAML
module.exports = require('./dist')
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist').YAML
module.exports = require('./dist')
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let moduleNameMapper
const testPathIgnorePatterns = ['tests/common', 'cst/common']
const testPathIgnorePatterns = ['tests/_import', 'cst/common']

// The npm script name is significant.
switch (process.env.npm_lifecycle_event) {
Expand Down
23 changes: 7 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { parse as parseCST } from './cst/parse.js'
import { Document } from './doc/Document.js'
import { YAMLSemanticError } from './errors.js'
import { defaultOptions, scalarOptions } from './options.js'
import { warn } from './warnings.js'

function parseAllDocuments(src, options) {
export { defaultOptions, scalarOptions } from './options.js'
export { Document, parseCST }

export function parseAllDocuments(src, options) {
const stream = []
let prev
for (const cstDoc of parseCST(src)) {
Expand All @@ -16,7 +18,7 @@ function parseAllDocuments(src, options) {
return stream
}

function parseDocument(src, options) {
export function parseDocument(src, options) {
const cst = parseCST(src)
const doc = new Document(cst[0], null, options)
if (cst.length > 1) {
Expand All @@ -27,7 +29,7 @@ function parseDocument(src, options) {
return doc
}

function parse(src, reviver, options) {
export function parse(src, reviver, options) {
if (options === undefined && reviver && typeof reviver === 'object') {
options = reviver
reviver = undefined
Expand All @@ -39,7 +41,7 @@ function parse(src, reviver, options) {
return doc.toJS({ reviver })
}

function stringify(value, replacer, options) {
export function stringify(value, replacer, options) {
if (typeof options === 'string') options = options.length
if (typeof options === 'number') {
const indent = Math.round(options)
Expand All @@ -51,14 +53,3 @@ function stringify(value, replacer, options) {
}
return new Document(value, replacer, options).toString()
}

export const YAML = {
defaultOptions,
Document,
parse,
parseAllDocuments,
parseCST,
parseDocument,
scalarOptions,
stringify
}
2 changes: 1 addition & 1 deletion tests/doc/YAML-1.1.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { source } from 'common-tags'
import YAML from '../../index.js'
import * as YAML from '../../index.js'

const orig = {}
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion tests/doc/YAML-1.2.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import YAML from '../../index.js'
import * as YAML from '../../index.js'
import { YAMLError } from '../../util.js'

const collectionKeyWarning =
Expand Down
2 changes: 1 addition & 1 deletion tests/doc/anchors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import YAML from '../../index.js'
import * as YAML from '../../index.js'
import { Merge, YAMLMap } from '../../types.js'

test('basic', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/doc/collection-access.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import YAML from '../../index.js'
import * as YAML from '../../index.js'
import { Pair } from '../../types.js'

describe('Map', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/doc/comments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { source } from 'common-tags'
import YAML from '../../index.js'
import * as YAML from '../../index.js'
import { Pair } from '../../types.js'

describe('parse comments', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/doc/createNode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { YAML } from '../../src/index.js'
import * as YAML from '../../src/index.js'
import { Pair, Scalar, YAMLMap, YAMLSeq } from '../../src/ast/index.js'
import { YAMLSet } from '../../src/tags/yaml-1.1/set.js'

Expand Down
2 changes: 1 addition & 1 deletion tests/doc/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Node } from '../../src/cst/Node.js'
import { YAMLError } from '../../src/errors.js'
import { YAML } from '../../src/index.js'
import * as YAML from '../../src/index.js'

let origPrettyErrors
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion tests/doc/foldFlowLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
FOLD_FLOW,
FOLD_QUOTED
} from '../../src/stringify/foldFlowLines.js'
import { YAML } from '../../src/index.js'
import * as YAML from '../../src/index.js'

describe('plain', () => {
const src = 'abc def ghi jkl mno pqr stu vwx yz\n'
Expand Down
2 changes: 1 addition & 1 deletion tests/doc/parse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'
import YAML from '../../index.js'
import * as YAML from '../../index.js'

describe('tags', () => {
describe('implicit tags', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/doc/stringify.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global BigInt */

import { source } from 'common-tags'
import YAML from '../../index.js'
import * as YAML from '../../index.js'
import { Pair, Scalar } from '../../types.js'
import { Type, stringifyString } from '../../util.js'

Expand Down
2 changes: 1 addition & 1 deletion tests/doc/types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { YAML } from '../../src/index.js'
import * as YAML from '../../src/index.js'
import { Scalar, YAMLSeq } from '../../src/ast/index.js'
import { binary } from '../../src/tags/yaml-1.1/binary.js'
import { YAMLOMap } from '../../src/tags/yaml-1.1/omap.js'
Expand Down
2 changes: 1 addition & 1 deletion tests/properties.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import YAML from '../index.js'
import * as fc from 'fast-check'
import * as YAML from '../index.js'

describe('properties', () => {
test('parse stringified object', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/yaml-test-suite.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'

import YAML from '../index.js'
import * as YAML from '../index.js'
import { testEvents } from '../dist/test-events.js'

const testDirs = fs
Expand Down

0 comments on commit eb8f0d3

Please sign in to comment.