Registry / devops / js-yaml-cloudformation-schema

js-yaml-cloudformation-schema

JSON →
library1.0.0jsnpmunverified

A custom schema for js-yaml (v1.0.0) that enables parsing and dumping of YAML CloudFormation templates using short-form intrinsic function syntax (e.g., !Ref, !Base64). It bridges YAML local tags to their JSON-compatible representation, ensuring parsed output matches JSON CloudFormation templates exactly. The package is stable but rarely updated, and is a fork of yyolk/cloudformation-js-yaml-schema with structural changes. Key differentiator: provides a ready-to-use schema that eliminates manual tag handling for AWS CloudFormation templates.

npm install js-yaml-cloudformation-schema
INSTALL
IMPORT
SIG · JS-YAML-CLOUDFORMA
J
js-yaml-cloudformation-schema
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CLOUDFORMATION_SCHEMA
import { CLOUDFORMATION_SCHEMA } from 'js-yaml-cloudformation-schema'
const CLOUDFORMATION_SCHEMA = require('js-yaml-cloudformation-schema')
This package is ESM-only. CommonJS require will not work. Use ES module import or dynamic import.
js-yaml (safeLoad)
import yaml from 'js-yaml'; const data = yaml.safeLoad(source, { schema: CLOUDFORMATION_SCHEMA })
const yaml = require('js-yaml'); const data = yaml.load(source)
Always pass the schema option. Without it, short-form tags like !Ref will not be parsed correctly. Use safeLoad (not load) for security.
js-yaml (safeDump)
const yamlOutput = yaml.safeDump(data, { schema: CLOUDFORMATION_SCHEMA })
const yamlOutput = yaml.safeDump(data)
Dumping also requires the schema option to preserve short-form syntax in the output.

Reads a CloudFormation YAML template, parses short-form intrinsics, and dumps back to YAML preserving syntax.

import fs from 'fs'; import yaml from 'js-yaml'; import { CLOUDFORMATION_SCHEMA } from 'js-yaml-cloudformation-schema'; const templatePath = process.env.TEMPLATE_PATH || 'template.yaml'; const templateBody = fs.readFileSync(templatePath, 'utf8'); const parsed = yaml.safeLoad(templateBody, { schema: CLOUDFORMATION_SCHEMA }); console.log('Parsed JSON:', JSON.stringify(parsed, null, 2)); const dumped = yaml.safeDump(parsed, { schema: CLOUDFORMATION_SCHEMA }); console.log('Dumped YAML:', dumped);
Debug
Known issues
breakingThis package is ESM-only (type: module in package.json). Using require() will throw an error.
fix
Use ES module import syntax (import) for this package. If you must use CommonJS, use dynamic import: const { CLOUDFORMATION_SCHEMA } = await import('js-yaml-cloudformation-schema');
affects: >=1.0.0
deprecatedjs-yaml's safeLoad and safeDump are deprecated in js-yaml v4. Use yaml.load and yaml.dump with schema option instead.
fix
Use yaml.load and yaml.dump from js-yaml v4, still passing schema: CLOUDFORMATION_SCHEMA.
affects: >=1.0.0 (js-yaml v4+)
gotchaThis schema only handles short-form intrinsic functions (e.g., !Ref, !Base64). Standard CloudFormation functions (Fn::Sub, etc.) are not supported in short form.
fix
Use the YAML short-form tags listed in the package's tags.json. For other functions, use the full Fn:: format.
affects: >=1.0.0
gotchaThe package has not been updated since initial release; it may not support newer js-yaml versions beyond v4.
fix
Test compatibility with your js-yaml version. If issues arise, consider pinning js-yaml to v3 or using a maintained alternative.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'js-yaml-cloudformation-schema' or its corresponding type declarations
The package is ESM-only and TypeScript may not resolve types correctly without configuration.
fix
Ensure your tsconfig.json has 'moduleResolution': 'node' or 'bundler' and 'esModuleInterop': true. Add 'allowSyntheticDefaultImports': true if needed.
CLOUDFORMATION_SCHEMA is not defined / Property 'CLOUDFORMATION_SCHEMA' does not exist on type 'typeof import("js-yaml-cloudformation-schema")'
Using CommonJS require instead of ES import, or type definitions not loaded.
fix
Use import { CLOUDFORMATION_SCHEMA } from 'js-yaml-cloudformation-schema'. If using require, use dynamic import: const { CLOUDFORMATION_SCHEMA } = await import('js-yaml-cloudformation-schema');
YAMLException: unknown tag !Ref (at line X, column Y)
The CLOUDFORMATION_SCHEMA was not passed to yaml.safeLoad.
fix
Pass the schema option: yaml.safeLoad(source, { schema: CLOUDFORMATION_SCHEMA })
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
js-yamlrequiredPeer dependency; the schema is designed to be used with js-yaml's safeLoad/safeDump methods.
Agent activity
6 hits · last 30 days
node
6
Resources
js-yaml-cloudformation-schema — npm install js-yaml-cloudformation-schema · libregistry