Skip to content

Issue 308 raw string support#321

Open
yilmazhasan wants to merge 1 commit into
toon-format:mainfrom
yilmazhasan:issue-308-raw-string-support
Open

Issue 308 raw string support#321
yilmazhasan wants to merge 1 commit into
toon-format:mainfrom
yilmazhasan:issue-308-raw-string-support

Conversation

@yilmazhasan

Copy link
Copy Markdown

Linked Issue

Closes #308

Description

The feature is to let toon output in a quoted way regardless of the type of the item, upon explicit argument is set.

Example:

const replacer: EncodeReplacer = (_k, v) => (typeof v === 'string' ? rawString(`"${v}"`) : v)
expect(encode({ id: '123' }, { replacer })).toBe('id: "123"')

Previously it was outputting 'id: 123', with this change it's possible to output 'id: "123"'

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Changes Made

  • escapeString is now exported from toon-format/toon/index.ts
  • RawString, rawString is implemented and exported from toon-format/toon/index.ts.

SPEC Compliance

  • This PR implements/fixes spec compliance
  • Spec section(s) affected:
  • Spec version:

Testing

  • Test cases added: raw-string.test.ts

  • All existing tests pass

  • Added new tests for changes

  • Tests cover edge cases and spec compliance

Pre-submission Checklist

  • My code follows the project's coding standards
  • I have run code formatting/linting tools
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation if needed
  • I have reviewed the TOON specification for relevant sections

Breaking Changes

  • No breaking changes
  • Breaking changes (describe migration path below)

Additional Context

The issue #308 has been implemented with this PR.

It was a requirement to let toon to output quoted strings when replacer is customized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(encode): expose rawString export for replacer

1 participant