File tree Expand file tree Collapse file tree 3 files changed +8
-5
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +8
-5
lines changed
Original file line number Diff line number Diff line change @@ -90,8 +90,8 @@ A function which can optionally mutate parsed YAML. The function should return t
90
90
91
91
``` js
92
92
yaml ({
93
- transform (data ) {
94
- if (Array .isArray (data)) {
93
+ transform (data , filePath ) {
94
+ if (Array .isArray (data) && filePath === ' ./my-file.yml ' ) {
95
95
return data .filter (character => ! character .batman );
96
96
}
97
97
}
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ const defaults = {
9
9
} ;
10
10
const ext = / \. y a ? m l $ / ;
11
11
12
- export default function yamll ( opts = { } ) {
12
+ export default function yaml ( opts = { } ) {
13
13
const options = Object . assign ( { } , defaults , opts ) ;
14
14
const { documentMode, safe } = options ;
15
15
const filter = createFilter ( options . include , options . exclude ) ;
@@ -35,7 +35,7 @@ export default function yamll(opts = {}) {
35
35
let data = loadMethod ( content ) ;
36
36
37
37
if ( typeof options . transform === 'function' ) {
38
- const result = options . transform ( data ) ;
38
+ const result = options . transform ( data , id ) ;
39
39
// eslint-disable-next-line no-undefined
40
40
if ( result !== undefined ) {
41
41
data = result ;
Original file line number Diff line number Diff line change @@ -59,8 +59,11 @@ test('resolves extensionless imports in conjunction with nodeResolve plugin', as
59
59
} ) ;
60
60
61
61
test ( 'applies the optional transform method to parsed YAML' , async ( t ) => {
62
- const transform = ( data ) => {
62
+ const transform = ( data , filePath ) => {
63
+ // check that transformer is passed a correct file path
64
+ t . true ( typeof filePath === 'string' && filePath . endsWith ( '.yaml' ) , filePath ) ;
63
65
if ( Array . isArray ( data ) ) {
66
+ t . true ( filePath . endsWith ( 'array.yaml' ) , filePath ) ;
64
67
return data . filter ( ( datum ) => ! datum . private ) ;
65
68
}
66
69
Object . keys ( data ) . forEach ( ( key ) => {
You can’t perform that action at this time.
0 commit comments