Split exports into 2 files : browser and node
This commit is contained in:
parent
652c001776
commit
b2179513f5
@ -2,7 +2,8 @@
|
||||
"name": "ods-xlsx",
|
||||
"version": "0.5.0",
|
||||
"type": "module",
|
||||
"main": "./scripts/main.js",
|
||||
"main": "./scripts/node.js",
|
||||
"browser": "./scripts/browser.js",
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"dev": "npm-run-all --parallel dev:* start",
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<script>
|
||||
//@ts-check
|
||||
|
||||
import {tableRawContentToObjects, tableWithoutEmptyRows, getODSTableRawContent, getXLSXTableRawContent} from './main.js'
|
||||
import {tableRawContentToObjects, tableWithoutEmptyRows, getODSTableRawContent, getXLSXTableRawContent} from './browser.js'
|
||||
|
||||
const ODS_TYPE = "application/vnd.oasis.opendocument.spreadsheet";
|
||||
const XLSX_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
|
||||
48
scripts/browser.js
Normal file
48
scripts/browser.js
Normal file
@ -0,0 +1,48 @@
|
||||
//@ts-check
|
||||
|
||||
function parseXML(str){
|
||||
return (new DOMParser()).parseFromString(str, 'application/xml');
|
||||
}
|
||||
|
||||
import {
|
||||
_getODSTableRawContent,
|
||||
_getXLSXTableRawContent
|
||||
} from './shared.js'
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} odsArrBuff
|
||||
* @returns {ReturnType<_getODSTableRawContent>}
|
||||
*/
|
||||
export function getODSTableRawContent(odsArrBuff){
|
||||
return _getODSTableRawContent(odsArrBuff, parseXML)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} xlsxArrBuff
|
||||
* @returns {ReturnType<_getXLSXTableRawContent>}
|
||||
*/
|
||||
export function getXLSXTableRawContent(xlsxArrBuff){
|
||||
return _getXLSXTableRawContent(xlsxArrBuff, parseXML)
|
||||
}
|
||||
|
||||
|
||||
export {
|
||||
// table-level exports
|
||||
tableWithoutEmptyRows,
|
||||
tableRawContentToValues,
|
||||
tableRawContentToStrings,
|
||||
tableRawContentToObjects,
|
||||
|
||||
// sheet-level exports
|
||||
sheetRawContentToObjects,
|
||||
sheetRawContentToStrings,
|
||||
|
||||
// row-level exports
|
||||
rowRawContentToStrings,
|
||||
isRowNotEmpty,
|
||||
|
||||
// cell-level exports
|
||||
cellRawContentToStrings,
|
||||
convertCellValue
|
||||
} from './shared.js'
|
||||
|
||||
@ -1,21 +1,9 @@
|
||||
//@ts-check
|
||||
|
||||
let _DOMParser
|
||||
|
||||
if(typeof DOMParser !== 'undefined' && Object(DOMParser) === DOMParser && DOMParser.prototype && typeof DOMParser.prototype.parseFromString === 'function'){
|
||||
//console.info('[ods-xlsx] Already existing DOMParser. Certainly in the browser')
|
||||
|
||||
_DOMParser = DOMParser
|
||||
}
|
||||
else{
|
||||
//console.info('[ods-xlsx] No native DOMParser. Certainly in Node.js')
|
||||
|
||||
const xmldom = await import('@xmldom/xmldom')
|
||||
_DOMParser = xmldom.DOMParser
|
||||
}
|
||||
import {DOMParser} from '@xmldom/xmldom'
|
||||
|
||||
function parseXML(str){
|
||||
return (new _DOMParser()).parseFromString(str, 'application/xml');
|
||||
return (new DOMParser()).parseFromString(str, 'application/xml');
|
||||
}
|
||||
|
||||
import {
|
||||
@ -2,7 +2,7 @@ import {readFile} from 'node:fs/promises'
|
||||
|
||||
import test from 'ava';
|
||||
|
||||
import {getODSTableRawContent} from '../scripts/main.js'
|
||||
import {getODSTableRawContent} from '../scripts/node.js'
|
||||
|
||||
const nomAgeContent = (await readFile('./tests/data/nom-age.ods')).buffer
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import {readFile} from 'node:fs/promises'
|
||||
|
||||
import test from 'ava';
|
||||
|
||||
import {getODSTableRawContent} from '../scripts/main.js'
|
||||
import {getODSTableRawContent} from '../scripts/node.js'
|
||||
|
||||
test('.ods file with table:number-columns-repeated attribute in cell', async t => {
|
||||
const repeatedCellFileContent = (await readFile('./tests/data/cellules-répétées.ods')).buffer
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user