Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove YAML.defaultOptions #346

Merged
merged 1 commit into from Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'
}