csv_4180
Version:
CSV according to RFC 4180. Everyone else's are weirdly wrong. Heavily tested; in typescript
32 lines • 2.66 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const ava_spec_1 = require("ava-spec");
const to_csv_1 = require("../to_csv");
ava_spec_1.describe('stringify', (it) => __awaiter(this, void 0, void 0, function* () {
it("abc/123", t => t.is('a,b,c\r\n1,2,3', to_csv_1.stringify([['a', 'b', 'c'], ['1', '2', '3']])));
it("embedded cr", t => t.is('a,"b\rc",d\r\n1,2,3', to_csv_1.stringify([['a', 'b\rc', 'd'], ['1', '2', '3']])));
it("embedded nl", t => t.is('a,"b\nc",d\r\n1,2,3', to_csv_1.stringify([['a', 'b\nc', 'd'], ['1', '2', '3']])));
it("embedded crnl", t => t.is('a,"b\r\nc",d\r\n1,2,3', to_csv_1.stringify([['a', 'b\r\nc', 'd'], ['1', '2', '3']])));
it("embedded quote", t => t.is('a,"b""c",d\r\n1,2,3', to_csv_1.stringify([['a', 'b"c', 'd'], ['1', '2', '3']])));
it("embedded twoquote", t => t.is('a,"b""""c",d\r\n1,2,3', to_csv_1.stringify([['a', 'b""c', 'd'], ['1', '2', '3']])));
it("with quoter", t => t.is('"a","b","c"\r\n"1","2","3"', to_csv_1.stringify([['a', 'b', 'c'], ['1', '2', '3']], { quoter: to_csv_1.quoteAlways })));
it("with headers", t => t.is('X,Y,Z\r\na,b,c\r\n1,2,3', to_csv_1.stringify([['a', 'b', 'c'], ['1', '2', '3']], { headers: ['X', 'Y', 'Z'] })));
it("with custom field separator", t => t.is('a;b;c\r\n1;2;3', to_csv_1.stringify([['a', 'b', 'c'], ['1', '2', '3']], { field_separator: ';' })));
it("with custom row separator", t => t.is('a,b,c---1,2,3', to_csv_1.stringify([['a', 'b', 'c'], ['1', '2', '3']], { row_separator: '---' })));
it("with trailing row separator", t => t.is('a,b,c\r\n1,2,3\r\n', to_csv_1.stringify([['a', 'b', 'c'], ['1', '2', '3']], { trailing_row_separator: true })));
it("with everything", t => t.is('"X";"Y";"Z"---"a";"b";"c"---"1";"2";"3"---', to_csv_1.stringify([['a', 'b', 'c'], ['1', '2', '3']], { quoter: to_csv_1.quoteAlways,
headers: ['X', 'Y', 'Z'],
field_separator: ';',
row_separator: '---',
trailing_row_separator: true
})));
}));
//# sourceMappingURL=stringify.js.map