Skip to content

Commit

Permalink
feat!: Remove YAML.defaultOptions (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Jan 8, 2022
1 parent b70f07a commit 7998a95
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
7 changes: 2 additions & 5 deletions src/compose/composer.ts
Expand Up @@ -2,8 +2,7 @@ import { Directives } from '../doc/directives.js'
import { Document } from '../doc/Document.js'
import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js'
import { isCollection, isPair, Range } from '../nodes/Node.js'
import {
defaultOptions,
import type {
DocumentOptions,
ParseOptions,
SchemaOptions
Expand Down Expand Up @@ -80,9 +79,7 @@ export class Composer {
private warnings: YAMLWarning[] = []

constructor(options: ParseOptions & DocumentOptions & SchemaOptions = {}) {
this.directives = new Directives({
version: options.version || defaultOptions.version
})
this.directives = new Directives({ version: options.version || '1.2' })
this.options = options
}

Expand Down
16 changes: 13 additions & 3 deletions src/doc/Document.ts
Expand Up @@ -16,9 +16,8 @@ import type { Scalar } from '../nodes/Scalar.js'
import { toJS, ToJSContext } from '../nodes/toJS.js'
import type { YAMLMap } from '../nodes/YAMLMap.js'
import type { YAMLSeq } from '../nodes/YAMLSeq.js'
import {
import type {
CreateNodeOptions,
defaultOptions,
DocumentOptions,
ParseOptions,
SchemaOptions,
Expand Down Expand Up @@ -111,7 +110,18 @@ export class Document<T = unknown> {
replacer = undefined
}

const opt = Object.assign({}, defaultOptions, options)
const opt = Object.assign(
{
intAsBigInt: false,
keepSourceTokens: false,
logLevel: 'warn',
prettyErrors: true,
strict: true,
uniqueKeys: true,
version: '1.2'
},
options
)
this.options = opt
let { version } = opt
if (options?.directives) {
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Expand Up @@ -24,9 +24,8 @@ export { Scalar } from './nodes/Scalar.js'
export { YAMLMap } from './nodes/YAMLMap.js'
export { YAMLSeq } from './nodes/YAMLSeq.js'

export {
export type {
CreateNodeOptions,
defaultOptions,
DocumentOptions,
ParseOptions,
SchemaOptions,
Expand Down
19 changes: 0 additions & 19 deletions src/options.ts
Expand Up @@ -372,22 +372,3 @@ export type ToStringOptions = {
*/
verifyAliasOrder?: boolean
}

/**
* `yaml` defines document-specific options in three places: as an argument of
* parse, create and stringify calls, in the values of `YAML.defaultOptions`,
* and in the version-dependent `YAML.Document.defaults` object. Values set in
* `YAML.defaultOptions` override version-dependent defaults, and argument
* options override both.
*/
export const defaultOptions: Required<
Omit<ParseOptions, 'lineCounter'> & Omit<DocumentOptions, 'directives'>
> = {
intAsBigInt: false,
keepSourceTokens: false,
logLevel: 'warn',
prettyErrors: true,
strict: true,
uniqueKeys: true,
version: '1.2'
}

0 comments on commit 7998a95

Please sign in to comment.