nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: callstack/react-native-paper
Pull request #496 (2018-08-17 12:23:55)

Fix issue with non-portal components appear above portal components (Material-next).


Patch:
diff --git a/src/components/Modal.js b/src/components/Modal.js
index 0026c8108..858caeb31 100644
--- a/src/components/Modal.js
+++ b/src/components/Modal.js
@@ -154,7 +154,9 @@ class Modal extends React.Component<Props, State> {
             <View style={StyleSheet.absoluteFill} />
           </TouchableWithoutFeedback>
         )}
-        <Animated.View style={[{ opacity: this.state.opacity }, styles.childrenWrapper]}>
+        <Animated.View
+          style={[{ opacity: this.state.opacity }, styles.childrenWrapper]}
+        >
           {children}
         </Animated.View>
       </Animated.View>
@@ -172,6 +174,6 @@ const styles = StyleSheet.create({
     justifyContent: 'center',
   },
   childrenWrapper: {
-    flex: 1
-  }
+    flex: 1,
+  },
 });
diff --git a/src/components/Portal/PortalHost.js b/src/components/Portal/PortalHost.js
index a119a73bc..5296c94c6 100644
--- a/src/components/Portal/PortalHost.js
+++ b/src/components/Portal/PortalHost.js
@@ -1,6 +1,7 @@
 /* @flow */
 
 import * as React from 'react';
+import { View, StyleSheet } from 'react-native';
 import PortalManager from './PortalManager';
 import createReactContext, { type Context } from 'create-react-context';
 
@@ -126,9 +127,18 @@ export default class PortalHost extends React.Component<Props> {
           unmount: this._unmount,
         }}
       >
-        {this.props.children}
+        {/* Need collapsable=false here to clip the elevations, otherwise they appear above Portal components */}
+        <View style={styles.container} collapsable={false}>
+          {this.props.children}
+        </View>
         <PortalManager ref={this._setManager} />
       </PortalContext.Provider>
     );
   }
 }
+
+const styles = StyleSheet.create({
+  container: {
+    flex: 1,
+  },
+});


Test patch:
diff --git a/src/components/__tests__/__snapshots__/Portal.test.js.snap b/src/components/__tests__/__snapshots__/Portal.test.js.snap
index 90ffcd0a6..afb9d276f 100644
--- a/src/components/__tests__/__snapshots__/Portal.test.js.snap
+++ b/src/components/__tests__/__snapshots__/Portal.test.js.snap
@@ -2,13 +2,22 @@
 
 exports[`renders portal with siblings 1`] = `
 Array [
-  <Text
-    accessible={true}
-    allowFontScaling={true}
-    ellipsizeMode="tail"
+  <View
+    collapsable={false}
+    style={
+      Object {
+        "flex": 1,
+      }
+    }
   >
-    Outside content
-  </Text>,
+    <Text
+      accessible={true}
+      allowFontScaling={true}
+      ellipsizeMode="tail"
+    >
+      Outside content
+    </Text>
+  </View>,
   <View
     pointerEvents="box-none"
     style={
Repository: callstack/react-native-paper
Pull request #673 (2018-11-22 15:24:48)

Update types.js


Patch:
diff --git a/src/components/Banner.js b/src/components/Banner.js
index 9ba4b2e16..04e9658fd 100644
--- a/src/components/Banner.js
+++ b/src/components/Banner.js
@@ -153,7 +153,15 @@ class Banner extends React.Component<Props, State> {
   };
 
   render() {
-    const { image, children, actions, style, ...rest } = this.props;
+    const {
+      visible,
+      image,
+      children,
+      actions,
+      style,
+      theme,
+      ...rest
+    } = this.props;
 
     const height = Animated.multiply(
       this.state.position,
diff --git a/src/components/Drawer/DrawerItem.js b/src/components/Drawer/DrawerItem.js
index 9c557cf21..06d103abf 100644
--- a/src/components/Drawer/DrawerItem.js
+++ b/src/components/Drawer/DrawerItem.js
@@ -7,10 +7,10 @@ import Text from '../Typography/Text';
 import Icon from '../Icon';
 import TouchableRipple from '../TouchableRipple';
 import { withTheme } from '../../core/theming';
-import type { Theme, $RemoveChildren } from '../../types';
+import type { Theme } from '../../types';
 import type { IconSource } from '../Icon';
 
-type Props = $RemoveChildren<typeof View> & {
+type Props = {
   /**
    * The label text of the item.
    */
diff --git a/src/types.js b/src/types.js
index c15fb0023..4d7dfda3e 100644
--- a/src/types.js
+++ b/src/types.js
@@ -1,5 +1,7 @@
 /* @flow */
 
+import * as React from 'react';
+
 export type Theme = {
   dark: boolean,
   roundness: number,


Test patch:
diff --git a/src/components/__tests__/__snapshots__/Banner.test.js.snap b/src/components/__tests__/__snapshots__/Banner.test.js.snap
index 8daf5ef86..ee192bf5b 100644
--- a/src/components/__tests__/__snapshots__/Banner.test.js.snap
+++ b/src/components/__tests__/__snapshots__/Banner.test.js.snap
@@ -15,7 +15,6 @@ exports[`renders hidden banner, without action buttons and without image 1`] = `
       "shadowRadius": 0.75,
     }
   }
-  visible={false}
 >
   <View
     style={
@@ -97,7 +96,6 @@ exports[`renders visible banner, with action buttons and with image 1`] = `
       "shadowRadius": 0.75,
     }
   }
-  visible={true}
 >
   <View
     style={
@@ -272,7 +270,6 @@ exports[`renders visible banner, with action buttons and without image 1`] = `
       "shadowRadius": 0.75,
     }
   }
-  visible={true}
 >
   <View
     style={
@@ -508,7 +505,6 @@ exports[`renders visible banner, without action buttons and with image 1`] = `
       "shadowRadius": 0.75,
     }
   }
-  visible={true}
 >
   <View
     style={
@@ -600,7 +596,6 @@ exports[`renders visible banner, without action buttons and without image 1`] =
       "shadowRadius": 0.75,
     }
   }
-  visible={true}
 >
   <View
     style={
Repository: callstack/react-native-paper
Pull request #750 (2019-01-23 12:37:48)

fix: replace 'orderRadius' with 'borderRadius' in Snackbar component
<!-- Please provide enough information so that others can review your pull request. -->
<!-- Keep pull requests small and focused on a single change. -->

### Motivation

The `borderRadius` / `roundness` prop was not working as expected because there was a typo in its name.

<!-- What existing problem does the pull request solve? Can you solve the issue with a different approach? -->

### Test plan

<!-- List the steps with which we can test this change. Provide screenshots if this changes anything visual. -->

n/a

callstack-bot: Hey @itsjgf, thank you for your pull request 🤗. The documentation from this branch can be viewed [here](https://7121-71323749-gh.circle-artifacts.com/0/docs/index.html). Please remember to update Typescript types if you changed API.
Trancever: Hi @itsjgf Thanks for PR. It looks like bug was introduced with [2b54b06bee105](https://github.com/callstack/react-native-paper/commit/2618c067f6e9ffdeed17ce7b12d2b54b06bee105)
Could you fix tests (yarn test -u) so we can proceed with merge?
itsjgf: @Trancever done

Patch:
diff --git a/src/components/Snackbar.js b/src/components/Snackbar.js
index 85bded913..65b560fc7 100644
--- a/src/components/Snackbar.js
+++ b/src/components/Snackbar.js
@@ -196,7 +196,7 @@ class Snackbar extends React.Component<Props, State> {
           style={[
             styles.container,
             {
-              orderRadius: roundness,
+              borderRadius: roundness,
               opacity: this.state.opacity,
               transform: [
                 {


Test patch:
diff --git a/src/components/__tests__/__snapshots__/Snackbar.test.js.snap b/src/components/__tests__/__snapshots__/Snackbar.test.js.snap
index a25e7c07e..8e05adf4d 100644
--- a/src/components/__tests__/__snapshots__/Snackbar.test.js.snap
+++ b/src/components/__tests__/__snapshots__/Snackbar.test.js.snap
@@ -26,7 +26,6 @@ exports[`renders snackbar with Text as a child 1`] = `
         "justifyContent": "space-between",
         "margin": 8,
         "opacity": 1,
-        "orderRadius": 4,
         "shadowColor": "#000000",
         "shadowOffset": Object {
           "height": 5,
@@ -98,7 +97,6 @@ exports[`renders snackbar with action button 1`] = `
         "justifyContent": "space-between",
         "margin": 8,
         "opacity": 1,
-        "orderRadius": 4,
         "shadowColor": "#000000",
         "shadowOffset": Object {
           "height": 5,
@@ -251,7 +249,6 @@ exports[`renders snackbar with content 1`] = `
         "justifyContent": "space-between",
         "margin": 8,
         "opacity": 1,
-        "orderRadius": 4,
         "shadowColor": "#000000",
         "shadowOffset": Object {
           "height": 5,
Repository: callstack/react-native-paper
Pull request #790 (2019-01-31 09:51:40)

fix: limit search bar input width
### Motivation

Once the search bar is set to a lower width, the input field is longer than expected on web. According to this https://bugzilla.mozilla.org/show_bug.cgi?id=1088586 a simple `minWidth: 0` should fix the issue.

### Test plan
Set the width of the search bar to e.g. 150.

Before:
![image](https://user-images.githubusercontent.com/5358638/52045990-f7b02c80-2545-11e9-946f-c601618ad758.png)

After:
![image](https://user-images.githubusercontent.com/5358638/52046063-1dd5cc80-2546-11e9-9e6c-4f2954d0e225.png)



Patch:
diff --git a/src/components/Searchbar.js b/src/components/Searchbar.js
index 498949a27..b3c64a9cb 100644
--- a/src/components/Searchbar.js
+++ b/src/components/Searchbar.js
@@ -192,6 +192,7 @@ const styles = StyleSheet.create({
     paddingLeft: 8,
     alignSelf: 'stretch',
     textAlign: I18nManager.isRTL ? 'right' : 'left',
+    minWidth: 0,
   },
 });
 


Test patch:
diff --git a/src/components/__tests__/__snapshots__/Searchbar.test.js.snap b/src/components/__tests__/__snapshots__/Searchbar.test.js.snap
index 700f30d63..2f37bce70 100644
--- a/src/components/__tests__/__snapshots__/Searchbar.test.js.snap
+++ b/src/components/__tests__/__snapshots__/Searchbar.test.js.snap
@@ -106,6 +106,7 @@ exports[`renders with placeholder 1`] = `
           "alignSelf": "stretch",
           "flex": 1,
           "fontSize": 18,
+          "minWidth": 0,
           "paddingLeft": 8,
           "textAlign": "left",
         },
@@ -305,6 +306,7 @@ exports[`renders with text 1`] = `
           "alignSelf": "stretch",
           "flex": 1,
           "fontSize": 18,
+          "minWidth": 0,
           "paddingLeft": 8,
           "textAlign": "left",
         },
Repository: callstack/react-native-paper
Pull request #858 (2019-02-21 09:23:53)

fix: makes FAB not pressable when initially not visible
Fix for #851 

[Snack](https://snack.expo.io/@trensik/bad-salsa) that reproduces issue.


Patch:
diff --git a/src/components/FAB/FAB.js b/src/components/FAB/FAB.js
index f1c4d3978..77730af4f 100644
--- a/src/components/FAB/FAB.js
+++ b/src/components/FAB/FAB.js
@@ -136,6 +136,7 @@ class FAB extends React.Component<Props, State> {
       onPress,
       theme,
       style,
+      visible,
       ...rest
     } = this.props;
     const { visibility } = this.state;
@@ -185,6 +186,7 @@ class FAB extends React.Component<Props, State> {
           disabled && styles.disabled,
           style,
         ]}
+        pointerEvents={visible ? 'auto' : 'none'}
       >
         <TouchableRipple
           borderless


Test patch:
diff --git a/src/components/__tests__/__snapshots__/FAB.test.js.snap b/src/components/__tests__/__snapshots__/FAB.test.js.snap
index 2be767320..4c7bdbb4a 100644
--- a/src/components/__tests__/__snapshots__/FAB.test.js.snap
+++ b/src/components/__tests__/__snapshots__/FAB.test.js.snap
@@ -2,6 +2,7 @@
 
 exports[`renders extended FAB 1`] = `
 <View
+  pointerEvents="auto"
   style={
     Object {
       "backgroundColor": "#03dac4",
@@ -22,7 +23,6 @@ exports[`renders extended FAB 1`] = `
       ],
     }
   }
-  visible={true}
 >
   <View
     accessibilityLabel="Add items"
@@ -159,6 +159,7 @@ exports[`renders extended FAB 1`] = `
 
 exports[`renders normal FAB 1`] = `
 <View
+  pointerEvents="auto"
   style={
     Object {
       "backgroundColor": "#03dac4",
@@ -179,7 +180,6 @@ exports[`renders normal FAB 1`] = `
       ],
     }
   }
-  visible={true}
 >
   <View
     accessibilityRole="button"
@@ -292,6 +292,7 @@ exports[`renders normal FAB 1`] = `
 
 exports[`renders small FAB 1`] = `
 <View
+  pointerEvents="auto"
   style={
     Object {
       "backgroundColor": "#03dac4",
@@ -312,7 +313,6 @@ exports[`renders small FAB 1`] = `
       ],
     }
   }
-  visible={true}
 >
   <View
     accessibilityRole="button"
Repository: mheap/pin-github-action
Pull request #195 (2025-03-18 11:36:53)

Add tests for addSecurity + fix allowlist format


Patch:
diff --git a/addSecurity.js b/addSecurity.js
index a6d5574..7349b27 100644
--- a/addSecurity.js
+++ b/addSecurity.js
@@ -1,5 +1,4 @@
-import fs from "fs/promises";
-
+import * as fs from "fs/promises";
 let workflow = `
 on: push
 
@@ -42,11 +41,12 @@ export default async function (filename, allowed, log) {
         repo = repo.slice(0, -1); // Remove the trailing *
       }
 
-      workflow += `\n            - ${repo}`;
+      workflow += `\n            ${repo}`;
     });
   }
   workflow += "\n";
 
   // Write the workflow to the file
   await fs.writeFile(filename, workflow);
+  return true;
 }


Test patch:
diff --git a/addSecurity.test.js b/addSecurity.test.js
new file mode 100644
index 0000000..76a6a01
--- /dev/null
+++ b/addSecurity.test.js
@@ -0,0 +1,53 @@
+import { beforeEach, jest } from "@jest/globals";
+import debugLib from "debug";
+const debug = debugLib("pin-github-action-test");
+
+jest.unstable_mockModule("fs/promises", () => ({
+  stat: jest.fn(),
+  writeFile: jest.fn(),
+}));
+
+beforeEach(() => {
+  jest.clearAllMocks();
+});
+
+const fs = await import("fs/promises");
+const { default: run } = await import("./addSecurity");
+
+const addSecurity = async (filename, allowed) => {
+  return run.apply(null, [filename, allowed, debug]);
+};
+
+test("writes config if file does not exist", async () => {
+  fs.stat.mockImplementation(() => {
+    return Promise.reject({ code: "ENOENT" });
+  });
+  fs.writeFile.mockImplementation(() => {
+    return Promise.resolve();
+  });
+  const actual = await addSecurity(".github/workflows/security.yaml", []);
+  expect(actual).toBe(true);
+});
+
+test("writes allowlisted config correctly", async () => {
+  fs.stat.mockImplementation(() => {
+    return Promise.reject({ code: "ENOENT" });
+  });
+  fs.writeFile.mockImplementation(() => {
+    return Promise.resolve();
+  });
+  await addSecurity(".github/workflows/security.yaml", [
+    "Demo1/*",
+    "Demo2/*",
+    "Demo3/*",
+  ]);
+  expect(fs.writeFile).toHaveBeenCalledWith(
+    ".github/workflows/security.yaml",
+    expect.stringContaining(`
+        with:
+          allowlist: |
+            Demo1/
+            Demo2/
+            Demo3/`),
+  );
+});
Repository: mheap/pin-github-action
Pull request #198 (2025-03-19 06:53:29)

Fix regex for adding pins
Do not replace comments on subsequent lines


Patch:
diff --git a/replaceActions.js b/replaceActions.js
index 1c76385..fe674ec 100644
--- a/replaceActions.js
+++ b/replaceActions.js
@@ -12,7 +12,7 @@ export default function (input, action, comment) {
   const regexpUpdate = new RegExp(
     `uses(\\s*):(\\s+)${quotePattern}${escapeStringRegexp(
       actionId,
-    )}@${escapeStringRegexp(currentVersion)}\\3(\\s*)#[^\\n]*`,
+    )}@${escapeStringRegexp(currentVersion)}\\3([\\t ]*)#[^\\n]*`,
     "g",
   );
 


Test patch:
diff --git a/replaceActions.test.js b/replaceActions.test.js
index 8b36333..efeef6e 100644
--- a/replaceActions.test.js
+++ b/replaceActions.test.js
@@ -369,6 +369,37 @@ jobs:
   expect(actual).toContain("uses: 'mheap/test-action@sha-two' # v1");
 });
 
+test("does not replace comments on the next line", () => {
+  let input = `name: PR
+on:
+  - pull_request
+jobs:
+  test-job:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: mheap/test-action@master
+
+      # This is a comment that should be untouched
+      - uses: mheap/test-action@master
+`;
+
+  let expected = `name: PR
+on:
+  - pull_request
+jobs:
+  test-job:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: mheap/test-action@sha-here # master
+
+      # This is a comment that should be untouched
+      - uses: mheap/test-action@sha-here # master
+`;
+
+  let actual = replaceActions(input, { ...action });
+  expect(actual).toBe(expected);
+});
+
 function convertToYaml(input) {
   return YAML.stringify(input);
 }
Repository: mholt/PapaParse
Pull request #281 (2016-01-21 00:59:16)

Fixes auto detecting mixed line endings
This stems from a production issue we faced while using PapaParse.  Customers had uploaded data with mixed line endings (likely due to a concat from different systems).  We were most interested in extracting header info, so this fix was better than the current guessing mechanism.  Still room for improvement.


Patch:
diff --git a/papaparse.js b/papaparse.js
index 21fd039..1761750 100644
--- a/papaparse.js
+++ b/papaparse.js
@@ -949,7 +949,11 @@
 
 			var r = input.split('\r');
 
-			if (r.length === 1)
+			var n = input.split('\n');
+
+			var nAppearsFirst = (n.length > 1 && n[0].length < r[0].length);
+
+			if (r.length === 1 || nAppearsFirst)
 				return '\n';
 
 			var numWithN = 0;


Test patch:
diff --git a/tests/test-cases.js b/tests/test-cases.js
index 2cbfa9a..eaa2145 100644
--- a/tests/test-cases.js
+++ b/tests/test-cases.js
@@ -507,6 +507,14 @@ var PARSE_TESTS = [
 			errors: []
 		}
 	},
+	{
+		description: "Mixed slash n and slash r should choose first as precident",
+		input: 'a,b,c\nd,e,f\rg,h,i\n',
+		expected: {
+			data: [['a', 'b', 'c'], ['d', 'e', 'f\rg', 'h', 'i'], ['']],
+			errors: []
+		}
+	},
 	{
 		description: "Header row with one row of data",
 		input: 'A,B,C\r\na,b,c',
Repository: mholt/PapaParse
Pull request #318 (2016-07-01 11:03:45)

Add callback option for specifying delimiter.
I noticed there are some difficulties with auto-detecting delimiters (best described at https://github.com/mholt/PapaParse/issues/153 & https://github.com/mholt/PapaParse/issues/290).

I've faced similar issues, but I can't follow the suggestion of specifying the delimiter every time, because I don't know it before parsing the file.

However I do, in my case, have a good idea of what structure the data will be in - for example I always expect the first cell to be empty (and can handle the errors arising from that ever not being true).

This lead me to the idea of allowing a callback to be used to determine the delimiter, based on the parsed file content (before it is parsed to CSV). This lets me simply return the first character of the input to specify the delimiter, rather than having to hard-code it or rely on auto-detection.

Let me know if you think this is an acceptable solution, and if it can be improved in anyway.



Patch:
diff --git a/papaparse.js b/papaparse.js
index 0537e0c..89d3cbe 100644
--- a/papaparse.js
+++ b/papaparse.js
@@ -764,6 +764,11 @@
 				}
 				_results.meta.delimiter = _config.delimiter;
 			}
+			else if(typeof _config.delimiter === 'function')
+			{
+				_config.delimiter = _config.delimiter(input);
+				_results.meta.delimiter = _config.delimiter;
+			}
 
 			var parserConfig = copy(_config);
 			if (_config.preview && _config.header)


Test patch:
diff --git a/tests/test-cases.js b/tests/test-cases.js
index 4f98590..44e0099 100644
--- a/tests/test-cases.js
+++ b/tests/test-cases.js
@@ -625,6 +625,15 @@ var PARSE_TESTS = [
 			errors: []
 		}
 	},
+	{
+		description: "Callback delimiter",
+		input: 'a$ b$ c',
+		config: { delimiter: function(input) { return input[1] + ' '; } },
+		expected: {
+			data: [['a', 'b', 'c']],
+			errors: []
+		}
+	},
 	{
 		description: "Dynamic typing converts numeric literals",
 		input: '1,2.2,1e3\r\n-4,-4.5,-4e-5\r\n-,5a,5-2',
Repository: mholt/PapaParse
Pull request #329 (2016-07-28 06:53:42)

Add custom quote character to unparse
Allows specifying the quoteChar in config for unparse like:

``` javascript
Papa.unparse(data, {
  quoteChar: "'"
})
```


pokoli: @prayashm the branch now has confilcts with latest code, could you please update them? 

Thanks! 
prayashm: Done :smiley: 

Happy to see you here!

Patch:
diff --git a/papaparse.js b/papaparse.js
index d0dbef1..618d58d 100644
--- a/papaparse.js
+++ b/papaparse.js
@@ -243,8 +243,13 @@
 		/** newline character(s) */
 		var _newline = '\r\n';
 
+		/** quote character */
+		var _quoteChar = '"';
+
 		unpackConfig();
 
+		var quoteCharRegex = new RegExp(_quoteChar, 'g');
+
 		if (typeof _input === 'string')
 			_input = JSON.parse(_input);
 
@@ -300,6 +305,9 @@
 			if (typeof _config.newline === 'string')
 				_newline = _config.newline;
 
+			if (typeof _config.quoteChar === 'string')
+				_quoteChar = _config.quoteChar;
+
 			if (typeof _config.header === 'boolean')
 				_writeHeader = _config.header;
 		}
@@ -368,7 +376,7 @@
 			if (typeof str === 'undefined' || str === null)
 				return '';
 
-			str = str.toString().replace(/"/g, '""');
+			str = str.toString().replace(quoteCharRegex, _quoteChar+_quoteChar);
 
 			var needsQuotes = (typeof _quotes === 'boolean' && _quotes)
 							|| (_quotes instanceof Array && _quotes[col])
@@ -377,7 +385,7 @@
 							|| str.charAt(0) === ' '
 							|| str.charAt(str.length - 1) === ' ';
 
-			return needsQuotes ? '"' + str + '"' : str;
+			return needsQuotes ? _quoteChar + str + _quoteChar : str;
 		}
 
 		function hasAny(str, substrings)


Test patch:
diff --git a/tests/test-cases.js b/tests/test-cases.js
index 677ba82..e31571c 100644
--- a/tests/test-cases.js
+++ b/tests/test-cases.js
@@ -901,16 +901,16 @@ var PARSE_TESTS = [
 			errors: []
 		}
 	},
-    {
-        description: "Single quote as quote character",
-        notes: "Must parse correctly when single quote is specified as a quote character",
-        input: "a,b,'c,d'",
-        config: { quoteChar: "'"},
-        expected: {
-            data: [['a', 'b', 'c,d']],
-            errors: []
-        }
-    }
+	{
+		description: "Single quote as quote character",
+		notes: "Must parse correctly when single quote is specified as a quote character",
+		input: "a,b,'c,d'",
+		config: { quoteChar: "'"},
+		expected: {
+			data: [['a', 'b', 'c,d']],
+			errors: []
+		}
+	}
 ];
 
 describe('Parse Tests', function() {
@@ -1163,6 +1163,12 @@ var UNPARSE_TESTS = [
 		expected: 'Col1,Col2,Col3\r\na,,c'
 	},
 	{
+		description: "Custom quote character (single quote)",
+		input: [['a,d','b','c']],
+		config: { quoteChar: "'"},
+		expected: "'a,d',b,c"
+  },
+  {
 		description: "Don't print header if header:false option specified",
 		input: [{ "Col1": "a", "Col2": "b", "Col3": "c" }, { "Col1": "d", "Col2": "e", "Col3": "f" }],
 		config: { header: false },
Repository: mholt/PapaParse
Pull request #346 (2016-09-19 14:51:48)

[unparse] header-option.
For unparse: use the header: option to specify whether a header should be printed or not.



Patch:
diff --git a/papaparse.js b/papaparse.js
index 758026c..a88e325 100644
--- a/papaparse.js
+++ b/papaparse.js
@@ -234,6 +234,9 @@
 		/** whether to surround every datum with quotes */
 		var _quotes = false;
 
+		/** whether to write headers */
+		var _writeHeader = true;
+
 		/** delimiting character */
 		var _delimiter = ',';
 
@@ -296,6 +299,9 @@
 
 			if (typeof _config.newline === 'string')
 				_newline = _config.newline;
+
+			if (typeof _config.header === 'boolean')
+				_writeHeader = _config.header;
 		}
 
 
@@ -324,7 +330,7 @@
 			var dataKeyedByField = !(data[0] instanceof Array);
 
 			// If there a header row, write it first
-			if (hasHeader)
+			if (hasHeader && _writeHeader)
 			{
 				for (var i = 0; i < fields.length; i++)
 				{


Test patch:
diff --git a/tests/test-cases.js b/tests/test-cases.js
index 9dda6ff..4485808 100644
--- a/tests/test-cases.js
+++ b/tests/test-cases.js
@@ -1152,6 +1152,12 @@ var UNPARSE_TESTS = [
 		description: "JSON null is treated as empty value",
 		input: [{ "Col1": "a", "Col2": null, "Col3": "c" }],
 		expected: 'Col1,Col2,Col3\r\na,,c'
+	},
+	{
+		description: "Don't print header if header:false option specified",
+		input: [{ "Col1": "a", "Col2": "b", "Col3": "c" }, { "Col1": "d", "Col2": "e", "Col3": "f" }],
+		config: { header: false },
+		expected: 'a,b,c\r\nd,e,f'
 	}
 ];