Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
fix: store custom formats under name
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed May 2, 2018
1 parent 2ff32b0 commit d00d132
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export const getDefaults = (formats: CustomFormats) => {
Object.keys(formats).forEach(key => {
const format: CustomFormat = formats[key]
if (typeof format.defaultValue !== 'undefined') {
result[key] = format.defaultValue
// store values under name, not under original key
result[format.name] = format.defaultValue
}
})
return result
Expand Down
17 changes: 17 additions & 0 deletions test/formats-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getDefaults, CustomFormats, CustomFormat } from '../src/formats'
import test from 'ava'

test('defaults by name', t => {
const bar: CustomFormat = {
name: 'bar',
detect: /bar/,
description: 'custom format named "bar"',
defaultValue: 'my-value',
}
const formats: CustomFormats = {
foo: bar,
}
const defaults = getDefaults(formats)
t.is(defaults.foo, undefined, 'no default under key foo')
t.is(defaults.bar, bar.defaultValue, 'but there is one under name bar')
})

0 comments on commit d00d132

Please sign in to comment.