@vuu-ui/vuu-table-extras 2.1.16 → 2.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/node_modules/csv-parse/dist/esm/sync.js +3978 -0
- package/cjs/node_modules/csv-parse/dist/esm/sync.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/calculated-column/CalculatedColumnPanel.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/calculated-column/useCalculatedColumnPanel.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/calculated-column/useEditCalculatedColumn.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-edit-validators/CaseValidator.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-edit-validators/PatternValidator.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-renderers/background-cell/BackgroundCell.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-renderers/background-cell/BackgroundCellConfigurationEditor.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-renderers/background-cell/useDirection.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-renderers/button-cell/IconButtonCell.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-renderers/dropdown-cell/DropdownCell.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-renderers/lookup-cell/LookupCell.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-renderers/pct-progress-cell/PctProgressCell.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/cell-renderers/progress-cell/ProgressCell.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/ColumnExpressionInput.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/column-function-descriptors.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/column-language-parser/ColumnExpressionLanguage.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/column-language-parser/ColumnExpressionTreeWalker.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/column-language-parser/column-expression-parse-utils.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/column-language-parser/generated/column-parser.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/functionDocInfo.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/highlighting.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/theme.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/useColumnAutoComplete.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/useColumnExpressionEditor.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-expression-input/useColumnExpressionSuggestionProvider.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-formatting-settings/BaseNumericFormattingSettings.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-formatting-settings/ColumnFormattingPanel.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-formatting-settings/DateTimeFormattingSettings.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-formatting-settings/LongTypeFormattingSettings.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-menu/ColumnMenu.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-menu/column-menu-utils.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-menu/useColumnActions.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-picker/ColumnModel.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-picker/ColumnPicker.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-picker/ColumnPickerAction.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-picker/useColumnPicker.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-picker/useTableColumnPicker.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-settings-panel/ColumnNameLabel.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-settings-panel/ColumnSettingsPanel.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/column-settings-panel/useColumnSettings.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/CsvUpload.css.js +6 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/CsvUpload.css.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/CsvUpload.js +95 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/CsvUpload.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-constants.js +8 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-constants.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-errors.js +64 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-errors.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-parse.js +199 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-parse.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-schema-validation.js +100 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-schema-validation.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-upload-utils.js +86 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/parse/csv-upload-utils.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/useCsvUpload.js +306 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/useCsvUpload.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/useCsvUploadSessionPreview.js +73 -0
- package/cjs/packages/vuu-table-extras/src/csv-upload/useCsvUploadSessionPreview.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/datasource-stats/DatasourceStats.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/datasource-stats/useDatasourceStats.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/freeze-control/FreezeControl.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/freeze-control/FrozenBanner.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/freeze-control/freezeControlBadge.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/freeze-control/useFreezeControl.js.map +1 -0
- package/cjs/{index.js → packages/vuu-table-extras/src/index.js} +16 -0
- package/cjs/packages/vuu-table-extras/src/index.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/tabbed-table-config-panel/TabbedTableConfigPanel.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/tabbed-table-config-panel/TabbedTableSettingsAction.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/tabbed-table-config-panel/useTabbedTableConfigPanel.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/table-footer/TableFooter.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/table-provider/TableProvider.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/table-settings-panel/TableSettingsPanel.js.map +1 -0
- package/cjs/packages/vuu-table-extras/src/table-settings-panel/useTableSettings.js.map +1 -0
- package/esm/node_modules/csv-parse/dist/esm/sync.js +3974 -0
- package/esm/node_modules/csv-parse/dist/esm/sync.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/calculated-column/CalculatedColumnPanel.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/calculated-column/useCalculatedColumnPanel.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/calculated-column/useEditCalculatedColumn.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-edit-validators/CaseValidator.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-edit-validators/PatternValidator.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-renderers/background-cell/BackgroundCell.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-renderers/background-cell/BackgroundCellConfigurationEditor.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-renderers/background-cell/useDirection.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-renderers/button-cell/IconButtonCell.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-renderers/dropdown-cell/DropdownCell.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-renderers/lookup-cell/LookupCell.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-renderers/pct-progress-cell/PctProgressCell.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/cell-renderers/progress-cell/ProgressCell.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/ColumnExpressionInput.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/column-function-descriptors.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/column-language-parser/ColumnExpressionLanguage.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/column-language-parser/ColumnExpressionTreeWalker.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/column-language-parser/column-expression-parse-utils.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/column-language-parser/generated/column-parser.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/functionDocInfo.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/highlighting.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/theme.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/useColumnAutoComplete.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/useColumnExpressionEditor.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-expression-input/useColumnExpressionSuggestionProvider.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-formatting-settings/BaseNumericFormattingSettings.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-formatting-settings/ColumnFormattingPanel.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-formatting-settings/DateTimeFormattingSettings.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-formatting-settings/LongTypeFormattingSettings.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-menu/ColumnMenu.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-menu/column-menu-utils.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-menu/useColumnActions.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-picker/ColumnModel.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-picker/ColumnPicker.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-picker/ColumnPickerAction.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-picker/useColumnPicker.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-picker/useTableColumnPicker.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-settings-panel/ColumnNameLabel.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-settings-panel/ColumnSettingsPanel.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/column-settings-panel/useColumnSettings.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/CsvUpload.css.js +4 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/CsvUpload.css.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/CsvUpload.js +93 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/CsvUpload.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-constants.js +5 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-constants.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-errors.js +57 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-errors.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-parse.js +196 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-parse.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-schema-validation.js +97 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-schema-validation.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-upload-utils.js +76 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/parse/csv-upload-utils.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/useCsvUpload.js +304 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/useCsvUpload.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/useCsvUploadSessionPreview.js +71 -0
- package/esm/packages/vuu-table-extras/src/csv-upload/useCsvUploadSessionPreview.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/datasource-stats/DatasourceStats.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/datasource-stats/useDatasourceStats.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/freeze-control/FreezeControl.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/freeze-control/FrozenBanner.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/freeze-control/freezeControlBadge.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/freeze-control/useFreezeControl.js.map +1 -0
- package/esm/{index.js → packages/vuu-table-extras/src/index.js} +7 -0
- package/{cjs → esm/packages/vuu-table-extras/src}/index.js.map +1 -1
- package/esm/packages/vuu-table-extras/src/tabbed-table-config-panel/TabbedTableConfigPanel.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/tabbed-table-config-panel/TabbedTableSettingsAction.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/tabbed-table-config-panel/useTabbedTableConfigPanel.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/table-footer/TableFooter.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/table-provider/TableProvider.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/table-settings-panel/TableSettingsPanel.js.map +1 -0
- package/esm/packages/vuu-table-extras/src/table-settings-panel/useTableSettings.js.map +1 -0
- package/package.json +15 -14
- package/types/csv-upload/CsvUpload.d.ts +47 -0
- package/types/csv-upload/index.d.ts +7 -0
- package/types/csv-upload/parse/csv-constants.d.ts +2 -0
- package/types/csv-upload/parse/csv-errors.d.ts +46 -0
- package/types/csv-upload/parse/csv-parse.d.ts +11 -0
- package/types/csv-upload/parse/csv-schema-validation.d.ts +16 -0
- package/types/csv-upload/parse/csv-upload-utils.d.ts +21 -0
- package/types/csv-upload/parse/index.d.ts +5 -0
- package/types/csv-upload/useCsvUpload.d.ts +26 -0
- package/types/csv-upload/useCsvUploadSessionPreview.d.ts +10 -0
- package/types/index.d.ts +1 -0
- package/cjs/calculated-column/CalculatedColumnPanel.js.map +0 -1
- package/cjs/calculated-column/useCalculatedColumnPanel.js.map +0 -1
- package/cjs/calculated-column/useEditCalculatedColumn.js.map +0 -1
- package/cjs/cell-edit-validators/CaseValidator.js.map +0 -1
- package/cjs/cell-edit-validators/PatternValidator.js.map +0 -1
- package/cjs/cell-renderers/background-cell/BackgroundCell.js.map +0 -1
- package/cjs/cell-renderers/background-cell/BackgroundCellConfigurationEditor.js.map +0 -1
- package/cjs/cell-renderers/background-cell/useDirection.js.map +0 -1
- package/cjs/cell-renderers/button-cell/IconButtonCell.js.map +0 -1
- package/cjs/cell-renderers/dropdown-cell/DropdownCell.js.map +0 -1
- package/cjs/cell-renderers/lookup-cell/LookupCell.js.map +0 -1
- package/cjs/cell-renderers/pct-progress-cell/PctProgressCell.js.map +0 -1
- package/cjs/cell-renderers/progress-cell/ProgressCell.js.map +0 -1
- package/cjs/column-expression-input/ColumnExpressionInput.js.map +0 -1
- package/cjs/column-expression-input/column-function-descriptors.js.map +0 -1
- package/cjs/column-expression-input/column-language-parser/ColumnExpressionLanguage.js.map +0 -1
- package/cjs/column-expression-input/column-language-parser/ColumnExpressionTreeWalker.js.map +0 -1
- package/cjs/column-expression-input/column-language-parser/column-expression-parse-utils.js.map +0 -1
- package/cjs/column-expression-input/column-language-parser/generated/column-parser.js.map +0 -1
- package/cjs/column-expression-input/functionDocInfo.js.map +0 -1
- package/cjs/column-expression-input/highlighting.js.map +0 -1
- package/cjs/column-expression-input/theme.js.map +0 -1
- package/cjs/column-expression-input/useColumnAutoComplete.js.map +0 -1
- package/cjs/column-expression-input/useColumnExpressionEditor.js.map +0 -1
- package/cjs/column-expression-input/useColumnExpressionSuggestionProvider.js.map +0 -1
- package/cjs/column-formatting-settings/BaseNumericFormattingSettings.js.map +0 -1
- package/cjs/column-formatting-settings/ColumnFormattingPanel.js.map +0 -1
- package/cjs/column-formatting-settings/DateTimeFormattingSettings.js.map +0 -1
- package/cjs/column-formatting-settings/LongTypeFormattingSettings.js.map +0 -1
- package/cjs/column-menu/ColumnMenu.js.map +0 -1
- package/cjs/column-menu/column-menu-utils.js.map +0 -1
- package/cjs/column-menu/useColumnActions.js.map +0 -1
- package/cjs/column-picker/ColumnModel.js.map +0 -1
- package/cjs/column-picker/ColumnPicker.js.map +0 -1
- package/cjs/column-picker/ColumnPickerAction.js.map +0 -1
- package/cjs/column-picker/useColumnPicker.js.map +0 -1
- package/cjs/column-picker/useTableColumnPicker.js.map +0 -1
- package/cjs/column-settings-panel/ColumnNameLabel.js.map +0 -1
- package/cjs/column-settings-panel/ColumnSettingsPanel.js.map +0 -1
- package/cjs/column-settings-panel/useColumnSettings.js.map +0 -1
- package/cjs/datasource-stats/DatasourceStats.js.map +0 -1
- package/cjs/datasource-stats/useDatasourceStats.js.map +0 -1
- package/cjs/freeze-control/FreezeControl.js.map +0 -1
- package/cjs/freeze-control/FrozenBanner.js.map +0 -1
- package/cjs/freeze-control/freezeControlBadge.js.map +0 -1
- package/cjs/freeze-control/useFreezeControl.js.map +0 -1
- package/cjs/tabbed-table-config-panel/TabbedTableConfigPanel.js.map +0 -1
- package/cjs/tabbed-table-config-panel/TabbedTableSettingsAction.js.map +0 -1
- package/cjs/tabbed-table-config-panel/useTabbedTableConfigPanel.js.map +0 -1
- package/cjs/table-footer/TableFooter.js.map +0 -1
- package/cjs/table-provider/TableProvider.js.map +0 -1
- package/cjs/table-settings-panel/TableSettingsPanel.js.map +0 -1
- package/cjs/table-settings-panel/useTableSettings.js.map +0 -1
- package/esm/calculated-column/CalculatedColumnPanel.js.map +0 -1
- package/esm/calculated-column/useCalculatedColumnPanel.js.map +0 -1
- package/esm/calculated-column/useEditCalculatedColumn.js.map +0 -1
- package/esm/cell-edit-validators/CaseValidator.js.map +0 -1
- package/esm/cell-edit-validators/PatternValidator.js.map +0 -1
- package/esm/cell-renderers/background-cell/BackgroundCell.js.map +0 -1
- package/esm/cell-renderers/background-cell/BackgroundCellConfigurationEditor.js.map +0 -1
- package/esm/cell-renderers/background-cell/useDirection.js.map +0 -1
- package/esm/cell-renderers/button-cell/IconButtonCell.js.map +0 -1
- package/esm/cell-renderers/dropdown-cell/DropdownCell.js.map +0 -1
- package/esm/cell-renderers/lookup-cell/LookupCell.js.map +0 -1
- package/esm/cell-renderers/pct-progress-cell/PctProgressCell.js.map +0 -1
- package/esm/cell-renderers/progress-cell/ProgressCell.js.map +0 -1
- package/esm/column-expression-input/ColumnExpressionInput.js.map +0 -1
- package/esm/column-expression-input/column-function-descriptors.js.map +0 -1
- package/esm/column-expression-input/column-language-parser/ColumnExpressionLanguage.js.map +0 -1
- package/esm/column-expression-input/column-language-parser/ColumnExpressionTreeWalker.js.map +0 -1
- package/esm/column-expression-input/column-language-parser/column-expression-parse-utils.js.map +0 -1
- package/esm/column-expression-input/column-language-parser/generated/column-parser.js.map +0 -1
- package/esm/column-expression-input/functionDocInfo.js.map +0 -1
- package/esm/column-expression-input/highlighting.js.map +0 -1
- package/esm/column-expression-input/theme.js.map +0 -1
- package/esm/column-expression-input/useColumnAutoComplete.js.map +0 -1
- package/esm/column-expression-input/useColumnExpressionEditor.js.map +0 -1
- package/esm/column-expression-input/useColumnExpressionSuggestionProvider.js.map +0 -1
- package/esm/column-formatting-settings/BaseNumericFormattingSettings.js.map +0 -1
- package/esm/column-formatting-settings/ColumnFormattingPanel.js.map +0 -1
- package/esm/column-formatting-settings/DateTimeFormattingSettings.js.map +0 -1
- package/esm/column-formatting-settings/LongTypeFormattingSettings.js.map +0 -1
- package/esm/column-menu/ColumnMenu.js.map +0 -1
- package/esm/column-menu/column-menu-utils.js.map +0 -1
- package/esm/column-menu/useColumnActions.js.map +0 -1
- package/esm/column-picker/ColumnModel.js.map +0 -1
- package/esm/column-picker/ColumnPicker.js.map +0 -1
- package/esm/column-picker/ColumnPickerAction.js.map +0 -1
- package/esm/column-picker/useColumnPicker.js.map +0 -1
- package/esm/column-picker/useTableColumnPicker.js.map +0 -1
- package/esm/column-settings-panel/ColumnNameLabel.js.map +0 -1
- package/esm/column-settings-panel/ColumnSettingsPanel.js.map +0 -1
- package/esm/column-settings-panel/useColumnSettings.js.map +0 -1
- package/esm/datasource-stats/DatasourceStats.js.map +0 -1
- package/esm/datasource-stats/useDatasourceStats.js.map +0 -1
- package/esm/freeze-control/FreezeControl.js.map +0 -1
- package/esm/freeze-control/FrozenBanner.js.map +0 -1
- package/esm/freeze-control/freezeControlBadge.js.map +0 -1
- package/esm/freeze-control/useFreezeControl.js.map +0 -1
- package/esm/index.js.map +0 -1
- package/esm/tabbed-table-config-panel/TabbedTableConfigPanel.js.map +0 -1
- package/esm/tabbed-table-config-panel/TabbedTableSettingsAction.js.map +0 -1
- package/esm/tabbed-table-config-panel/useTabbedTableConfigPanel.js.map +0 -1
- package/esm/table-footer/TableFooter.js.map +0 -1
- package/esm/table-provider/TableProvider.js.map +0 -1
- package/esm/table-settings-panel/TableSettingsPanel.js.map +0 -1
- package/esm/table-settings-panel/useTableSettings.js.map +0 -1
- /package/cjs/{calculated-column → packages/vuu-table-extras/src/calculated-column}/CalculatedColumnPanel.js +0 -0
- /package/cjs/{calculated-column → packages/vuu-table-extras/src/calculated-column}/useCalculatedColumnPanel.js +0 -0
- /package/cjs/{calculated-column → packages/vuu-table-extras/src/calculated-column}/useEditCalculatedColumn.js +0 -0
- /package/cjs/{cell-edit-validators → packages/vuu-table-extras/src/cell-edit-validators}/CaseValidator.js +0 -0
- /package/cjs/{cell-edit-validators → packages/vuu-table-extras/src/cell-edit-validators}/PatternValidator.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCell.css.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCell.css.js.map +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCell.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCellConfigurationEditor.css.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCellConfigurationEditor.css.js.map +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCellConfigurationEditor.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundKeyframes.css.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundKeyframes.css.js.map +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/useDirection.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/button-cell/IconButtonCell.css.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/button-cell/IconButtonCell.css.js.map +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/button-cell/IconButtonCell.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/dropdown-cell/DropdownCell.css.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/dropdown-cell/DropdownCell.css.js.map +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/dropdown-cell/DropdownCell.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/lookup-cell/LookupCell.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/pct-progress-cell/PctProgressCell.css.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/pct-progress-cell/PctProgressCell.css.js.map +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/pct-progress-cell/PctProgressCell.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/progress-cell/ProgressCell.css.js +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/progress-cell/ProgressCell.css.js.map +0 -0
- /package/cjs/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/progress-cell/ProgressCell.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/ColumnExpressionInput.css.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/ColumnExpressionInput.css.js.map +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/ColumnExpressionInput.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-function-descriptors.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-language-parser/ColumnExpressionLanguage.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-language-parser/ColumnExpressionTreeWalker.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-language-parser/column-expression-parse-utils.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-language-parser/generated/column-parser.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/functionDocInfo.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/highlighting.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/theme.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/useColumnAutoComplete.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/useColumnExpressionEditor.js +0 -0
- /package/cjs/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/useColumnExpressionSuggestionProvider.js +0 -0
- /package/cjs/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/BaseNumericFormattingSettings.js +0 -0
- /package/cjs/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/ColumnFormattingPanel.js +0 -0
- /package/cjs/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/DateTimeFormattingSettings.js +0 -0
- /package/cjs/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/LongTypeFormattingSettings.css.js +0 -0
- /package/cjs/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/LongTypeFormattingSettings.css.js.map +0 -0
- /package/cjs/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/LongTypeFormattingSettings.js +0 -0
- /package/cjs/{column-menu → packages/vuu-table-extras/src/column-menu}/ColumnMenu.css.js +0 -0
- /package/cjs/{column-menu → packages/vuu-table-extras/src/column-menu}/ColumnMenu.css.js.map +0 -0
- /package/cjs/{column-menu → packages/vuu-table-extras/src/column-menu}/ColumnMenu.js +0 -0
- /package/cjs/{column-menu → packages/vuu-table-extras/src/column-menu}/column-menu-utils.js +0 -0
- /package/cjs/{column-menu → packages/vuu-table-extras/src/column-menu}/useColumnActions.js +0 -0
- /package/cjs/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnModel.js +0 -0
- /package/cjs/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnPicker.css.js +0 -0
- /package/cjs/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnPicker.css.js.map +0 -0
- /package/cjs/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnPicker.js +0 -0
- /package/cjs/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnPickerAction.js +0 -0
- /package/cjs/{column-picker → packages/vuu-table-extras/src/column-picker}/useColumnPicker.js +0 -0
- /package/cjs/{column-picker → packages/vuu-table-extras/src/column-picker}/useTableColumnPicker.js +0 -0
- /package/cjs/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnNameLabel.css.js +0 -0
- /package/cjs/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnNameLabel.css.js.map +0 -0
- /package/cjs/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnNameLabel.js +0 -0
- /package/cjs/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnSettingsPanel.css.js +0 -0
- /package/cjs/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnSettingsPanel.css.js.map +0 -0
- /package/cjs/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnSettingsPanel.js +0 -0
- /package/cjs/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/useColumnSettings.js +0 -0
- /package/cjs/{datasource-stats → packages/vuu-table-extras/src/datasource-stats}/DatasourceStats.css.js +0 -0
- /package/cjs/{datasource-stats → packages/vuu-table-extras/src/datasource-stats}/DatasourceStats.css.js.map +0 -0
- /package/cjs/{datasource-stats → packages/vuu-table-extras/src/datasource-stats}/DatasourceStats.js +0 -0
- /package/cjs/{datasource-stats → packages/vuu-table-extras/src/datasource-stats}/useDatasourceStats.js +0 -0
- /package/cjs/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FreezeControl.css.js +0 -0
- /package/cjs/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FreezeControl.css.js.map +0 -0
- /package/cjs/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FreezeControl.js +0 -0
- /package/cjs/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FrozenBanner.css.js +0 -0
- /package/cjs/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FrozenBanner.css.js.map +0 -0
- /package/cjs/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FrozenBanner.js +0 -0
- /package/cjs/{freeze-control → packages/vuu-table-extras/src/freeze-control}/freezeControlBadge.js +0 -0
- /package/cjs/{freeze-control → packages/vuu-table-extras/src/freeze-control}/useFreezeControl.js +0 -0
- /package/cjs/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/TabbedTableConfigPanel.css.js +0 -0
- /package/cjs/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/TabbedTableConfigPanel.css.js.map +0 -0
- /package/cjs/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/TabbedTableConfigPanel.js +0 -0
- /package/cjs/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/TabbedTableSettingsAction.js +0 -0
- /package/cjs/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/useTabbedTableConfigPanel.js +0 -0
- /package/cjs/{table-footer → packages/vuu-table-extras/src/table-footer}/TableFooter.css.js +0 -0
- /package/cjs/{table-footer → packages/vuu-table-extras/src/table-footer}/TableFooter.css.js.map +0 -0
- /package/cjs/{table-footer → packages/vuu-table-extras/src/table-footer}/TableFooter.js +0 -0
- /package/cjs/{table-provider → packages/vuu-table-extras/src/table-provider}/TableProvider.js +0 -0
- /package/cjs/{table-settings-panel → packages/vuu-table-extras/src/table-settings-panel}/TableSettingsPanel.css.js +0 -0
- /package/cjs/{table-settings-panel → packages/vuu-table-extras/src/table-settings-panel}/TableSettingsPanel.css.js.map +0 -0
- /package/cjs/{table-settings-panel → packages/vuu-table-extras/src/table-settings-panel}/TableSettingsPanel.js +0 -0
- /package/cjs/{table-settings-panel → packages/vuu-table-extras/src/table-settings-panel}/useTableSettings.js +0 -0
- /package/esm/{calculated-column → packages/vuu-table-extras/src/calculated-column}/CalculatedColumnPanel.js +0 -0
- /package/esm/{calculated-column → packages/vuu-table-extras/src/calculated-column}/useCalculatedColumnPanel.js +0 -0
- /package/esm/{calculated-column → packages/vuu-table-extras/src/calculated-column}/useEditCalculatedColumn.js +0 -0
- /package/esm/{cell-edit-validators → packages/vuu-table-extras/src/cell-edit-validators}/CaseValidator.js +0 -0
- /package/esm/{cell-edit-validators → packages/vuu-table-extras/src/cell-edit-validators}/PatternValidator.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCell.css.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCell.css.js.map +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCell.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCellConfigurationEditor.css.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCellConfigurationEditor.css.js.map +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundCellConfigurationEditor.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundKeyframes.css.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/BackgroundKeyframes.css.js.map +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/background-cell/useDirection.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/button-cell/IconButtonCell.css.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/button-cell/IconButtonCell.css.js.map +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/button-cell/IconButtonCell.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/dropdown-cell/DropdownCell.css.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/dropdown-cell/DropdownCell.css.js.map +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/dropdown-cell/DropdownCell.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/lookup-cell/LookupCell.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/pct-progress-cell/PctProgressCell.css.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/pct-progress-cell/PctProgressCell.css.js.map +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/pct-progress-cell/PctProgressCell.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/progress-cell/ProgressCell.css.js +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/progress-cell/ProgressCell.css.js.map +0 -0
- /package/esm/{cell-renderers → packages/vuu-table-extras/src/cell-renderers}/progress-cell/ProgressCell.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/ColumnExpressionInput.css.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/ColumnExpressionInput.css.js.map +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/ColumnExpressionInput.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-function-descriptors.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-language-parser/ColumnExpressionLanguage.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-language-parser/ColumnExpressionTreeWalker.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-language-parser/column-expression-parse-utils.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/column-language-parser/generated/column-parser.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/functionDocInfo.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/highlighting.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/theme.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/useColumnAutoComplete.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/useColumnExpressionEditor.js +0 -0
- /package/esm/{column-expression-input → packages/vuu-table-extras/src/column-expression-input}/useColumnExpressionSuggestionProvider.js +0 -0
- /package/esm/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/BaseNumericFormattingSettings.js +0 -0
- /package/esm/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/ColumnFormattingPanel.js +0 -0
- /package/esm/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/DateTimeFormattingSettings.js +0 -0
- /package/esm/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/LongTypeFormattingSettings.css.js +0 -0
- /package/esm/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/LongTypeFormattingSettings.css.js.map +0 -0
- /package/esm/{column-formatting-settings → packages/vuu-table-extras/src/column-formatting-settings}/LongTypeFormattingSettings.js +0 -0
- /package/esm/{column-menu → packages/vuu-table-extras/src/column-menu}/ColumnMenu.css.js +0 -0
- /package/esm/{column-menu → packages/vuu-table-extras/src/column-menu}/ColumnMenu.css.js.map +0 -0
- /package/esm/{column-menu → packages/vuu-table-extras/src/column-menu}/ColumnMenu.js +0 -0
- /package/esm/{column-menu → packages/vuu-table-extras/src/column-menu}/column-menu-utils.js +0 -0
- /package/esm/{column-menu → packages/vuu-table-extras/src/column-menu}/useColumnActions.js +0 -0
- /package/esm/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnModel.js +0 -0
- /package/esm/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnPicker.css.js +0 -0
- /package/esm/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnPicker.css.js.map +0 -0
- /package/esm/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnPicker.js +0 -0
- /package/esm/{column-picker → packages/vuu-table-extras/src/column-picker}/ColumnPickerAction.js +0 -0
- /package/esm/{column-picker → packages/vuu-table-extras/src/column-picker}/useColumnPicker.js +0 -0
- /package/esm/{column-picker → packages/vuu-table-extras/src/column-picker}/useTableColumnPicker.js +0 -0
- /package/esm/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnNameLabel.css.js +0 -0
- /package/esm/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnNameLabel.css.js.map +0 -0
- /package/esm/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnNameLabel.js +0 -0
- /package/esm/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnSettingsPanel.css.js +0 -0
- /package/esm/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnSettingsPanel.css.js.map +0 -0
- /package/esm/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/ColumnSettingsPanel.js +0 -0
- /package/esm/{column-settings-panel → packages/vuu-table-extras/src/column-settings-panel}/useColumnSettings.js +0 -0
- /package/esm/{datasource-stats → packages/vuu-table-extras/src/datasource-stats}/DatasourceStats.css.js +0 -0
- /package/esm/{datasource-stats → packages/vuu-table-extras/src/datasource-stats}/DatasourceStats.css.js.map +0 -0
- /package/esm/{datasource-stats → packages/vuu-table-extras/src/datasource-stats}/DatasourceStats.js +0 -0
- /package/esm/{datasource-stats → packages/vuu-table-extras/src/datasource-stats}/useDatasourceStats.js +0 -0
- /package/esm/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FreezeControl.css.js +0 -0
- /package/esm/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FreezeControl.css.js.map +0 -0
- /package/esm/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FreezeControl.js +0 -0
- /package/esm/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FrozenBanner.css.js +0 -0
- /package/esm/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FrozenBanner.css.js.map +0 -0
- /package/esm/{freeze-control → packages/vuu-table-extras/src/freeze-control}/FrozenBanner.js +0 -0
- /package/esm/{freeze-control → packages/vuu-table-extras/src/freeze-control}/freezeControlBadge.js +0 -0
- /package/esm/{freeze-control → packages/vuu-table-extras/src/freeze-control}/useFreezeControl.js +0 -0
- /package/esm/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/TabbedTableConfigPanel.css.js +0 -0
- /package/esm/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/TabbedTableConfigPanel.css.js.map +0 -0
- /package/esm/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/TabbedTableConfigPanel.js +0 -0
- /package/esm/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/TabbedTableSettingsAction.js +0 -0
- /package/esm/{tabbed-table-config-panel → packages/vuu-table-extras/src/tabbed-table-config-panel}/useTabbedTableConfigPanel.js +0 -0
- /package/esm/{table-footer → packages/vuu-table-extras/src/table-footer}/TableFooter.css.js +0 -0
- /package/esm/{table-footer → packages/vuu-table-extras/src/table-footer}/TableFooter.css.js.map +0 -0
- /package/esm/{table-footer → packages/vuu-table-extras/src/table-footer}/TableFooter.js +0 -0
- /package/esm/{table-provider → packages/vuu-table-extras/src/table-provider}/TableProvider.js +0 -0
- /package/esm/{table-settings-panel → packages/vuu-table-extras/src/table-settings-panel}/TableSettingsPanel.css.js +0 -0
- /package/esm/{table-settings-panel → packages/vuu-table-extras/src/table-settings-panel}/TableSettingsPanel.css.js.map +0 -0
- /package/esm/{table-settings-panel → packages/vuu-table-extras/src/table-settings-panel}/TableSettingsPanel.js +0 -0
- /package/esm/{table-settings-panel → packages/vuu-table-extras/src/table-settings-panel}/useTableSettings.js +0 -0
|
@@ -0,0 +1,3978 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var global$1 = (typeof global !== "undefined" ? global :
|
|
4
|
+
typeof self !== "undefined" ? self :
|
|
5
|
+
typeof window !== "undefined" ? window : {});
|
|
6
|
+
|
|
7
|
+
var lookup = [];
|
|
8
|
+
var revLookup = [];
|
|
9
|
+
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
|
|
10
|
+
var inited = false;
|
|
11
|
+
function init () {
|
|
12
|
+
inited = true;
|
|
13
|
+
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
14
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
15
|
+
lookup[i] = code[i];
|
|
16
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
revLookup['-'.charCodeAt(0)] = 62;
|
|
20
|
+
revLookup['_'.charCodeAt(0)] = 63;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toByteArray (b64) {
|
|
24
|
+
if (!inited) {
|
|
25
|
+
init();
|
|
26
|
+
}
|
|
27
|
+
var i, j, l, tmp, placeHolders, arr;
|
|
28
|
+
var len = b64.length;
|
|
29
|
+
|
|
30
|
+
if (len % 4 > 0) {
|
|
31
|
+
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// the number of equal signs (place holders)
|
|
35
|
+
// if there are two placeholders, than the two characters before it
|
|
36
|
+
// represent one byte
|
|
37
|
+
// if there is only one, then the three characters before it represent 2 bytes
|
|
38
|
+
// this is just a cheap hack to not do indexOf twice
|
|
39
|
+
placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
|
|
40
|
+
|
|
41
|
+
// base64 is 4/3 + up to two characters of the original data
|
|
42
|
+
arr = new Arr(len * 3 / 4 - placeHolders);
|
|
43
|
+
|
|
44
|
+
// if there are placeholders, only get up to the last complete 4 chars
|
|
45
|
+
l = placeHolders > 0 ? len - 4 : len;
|
|
46
|
+
|
|
47
|
+
var L = 0;
|
|
48
|
+
|
|
49
|
+
for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
|
50
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
|
|
51
|
+
arr[L++] = (tmp >> 16) & 0xFF;
|
|
52
|
+
arr[L++] = (tmp >> 8) & 0xFF;
|
|
53
|
+
arr[L++] = tmp & 0xFF;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (placeHolders === 2) {
|
|
57
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
|
|
58
|
+
arr[L++] = tmp & 0xFF;
|
|
59
|
+
} else if (placeHolders === 1) {
|
|
60
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
|
|
61
|
+
arr[L++] = (tmp >> 8) & 0xFF;
|
|
62
|
+
arr[L++] = tmp & 0xFF;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return arr
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function tripletToBase64 (num) {
|
|
69
|
+
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function encodeChunk (uint8, start, end) {
|
|
73
|
+
var tmp;
|
|
74
|
+
var output = [];
|
|
75
|
+
for (var i = start; i < end; i += 3) {
|
|
76
|
+
tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
|
|
77
|
+
output.push(tripletToBase64(tmp));
|
|
78
|
+
}
|
|
79
|
+
return output.join('')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function fromByteArray (uint8) {
|
|
83
|
+
if (!inited) {
|
|
84
|
+
init();
|
|
85
|
+
}
|
|
86
|
+
var tmp;
|
|
87
|
+
var len = uint8.length;
|
|
88
|
+
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
89
|
+
var output = '';
|
|
90
|
+
var parts = [];
|
|
91
|
+
var maxChunkLength = 16383; // must be multiple of 3
|
|
92
|
+
|
|
93
|
+
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
94
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
95
|
+
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
99
|
+
if (extraBytes === 1) {
|
|
100
|
+
tmp = uint8[len - 1];
|
|
101
|
+
output += lookup[tmp >> 2];
|
|
102
|
+
output += lookup[(tmp << 4) & 0x3F];
|
|
103
|
+
output += '==';
|
|
104
|
+
} else if (extraBytes === 2) {
|
|
105
|
+
tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
|
|
106
|
+
output += lookup[tmp >> 10];
|
|
107
|
+
output += lookup[(tmp >> 4) & 0x3F];
|
|
108
|
+
output += lookup[(tmp << 2) & 0x3F];
|
|
109
|
+
output += '=';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
parts.push(output);
|
|
113
|
+
|
|
114
|
+
return parts.join('')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function read (buffer, offset, isLE, mLen, nBytes) {
|
|
118
|
+
var e, m;
|
|
119
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
120
|
+
var eMax = (1 << eLen) - 1;
|
|
121
|
+
var eBias = eMax >> 1;
|
|
122
|
+
var nBits = -7;
|
|
123
|
+
var i = isLE ? (nBytes - 1) : 0;
|
|
124
|
+
var d = isLE ? -1 : 1;
|
|
125
|
+
var s = buffer[offset + i];
|
|
126
|
+
|
|
127
|
+
i += d;
|
|
128
|
+
|
|
129
|
+
e = s & ((1 << (-nBits)) - 1);
|
|
130
|
+
s >>= (-nBits);
|
|
131
|
+
nBits += eLen;
|
|
132
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
|
133
|
+
|
|
134
|
+
m = e & ((1 << (-nBits)) - 1);
|
|
135
|
+
e >>= (-nBits);
|
|
136
|
+
nBits += mLen;
|
|
137
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
|
138
|
+
|
|
139
|
+
if (e === 0) {
|
|
140
|
+
e = 1 - eBias;
|
|
141
|
+
} else if (e === eMax) {
|
|
142
|
+
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
143
|
+
} else {
|
|
144
|
+
m = m + Math.pow(2, mLen);
|
|
145
|
+
e = e - eBias;
|
|
146
|
+
}
|
|
147
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function write (buffer, value, offset, isLE, mLen, nBytes) {
|
|
151
|
+
var e, m, c;
|
|
152
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
153
|
+
var eMax = (1 << eLen) - 1;
|
|
154
|
+
var eBias = eMax >> 1;
|
|
155
|
+
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
|
|
156
|
+
var i = isLE ? 0 : (nBytes - 1);
|
|
157
|
+
var d = isLE ? 1 : -1;
|
|
158
|
+
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
159
|
+
|
|
160
|
+
value = Math.abs(value);
|
|
161
|
+
|
|
162
|
+
if (isNaN(value) || value === Infinity) {
|
|
163
|
+
m = isNaN(value) ? 1 : 0;
|
|
164
|
+
e = eMax;
|
|
165
|
+
} else {
|
|
166
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
167
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
168
|
+
e--;
|
|
169
|
+
c *= 2;
|
|
170
|
+
}
|
|
171
|
+
if (e + eBias >= 1) {
|
|
172
|
+
value += rt / c;
|
|
173
|
+
} else {
|
|
174
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
175
|
+
}
|
|
176
|
+
if (value * c >= 2) {
|
|
177
|
+
e++;
|
|
178
|
+
c /= 2;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (e + eBias >= eMax) {
|
|
182
|
+
m = 0;
|
|
183
|
+
e = eMax;
|
|
184
|
+
} else if (e + eBias >= 1) {
|
|
185
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
186
|
+
e = e + eBias;
|
|
187
|
+
} else {
|
|
188
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
189
|
+
e = 0;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
194
|
+
|
|
195
|
+
e = (e << mLen) | m;
|
|
196
|
+
eLen += mLen;
|
|
197
|
+
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
198
|
+
|
|
199
|
+
buffer[offset + i - d] |= s * 128;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
var toString = {}.toString;
|
|
203
|
+
|
|
204
|
+
var isArray = Array.isArray || function (arr) {
|
|
205
|
+
return toString.call(arr) == '[object Array]';
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
var INSPECT_MAX_BYTES = 50;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
212
|
+
* === true Use Uint8Array implementation (fastest)
|
|
213
|
+
* === false Use Object implementation (most compatible, even IE6)
|
|
214
|
+
*
|
|
215
|
+
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
216
|
+
* Opera 11.6+, iOS 4.2+.
|
|
217
|
+
*
|
|
218
|
+
* Due to various browser bugs, sometimes the Object implementation will be used even
|
|
219
|
+
* when the browser supports typed arrays.
|
|
220
|
+
*
|
|
221
|
+
* Note:
|
|
222
|
+
*
|
|
223
|
+
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
|
|
224
|
+
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
|
|
225
|
+
*
|
|
226
|
+
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
|
|
227
|
+
*
|
|
228
|
+
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
|
|
229
|
+
* incorrect length in some situations.
|
|
230
|
+
|
|
231
|
+
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
|
|
232
|
+
* get the Object implementation, which is slower but behaves correctly.
|
|
233
|
+
*/
|
|
234
|
+
Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
|
|
235
|
+
? global$1.TYPED_ARRAY_SUPPORT
|
|
236
|
+
: true;
|
|
237
|
+
|
|
238
|
+
/*
|
|
239
|
+
* Export kMaxLength after typed array support is determined.
|
|
240
|
+
*/
|
|
241
|
+
kMaxLength();
|
|
242
|
+
|
|
243
|
+
function kMaxLength () {
|
|
244
|
+
return Buffer.TYPED_ARRAY_SUPPORT
|
|
245
|
+
? 0x7fffffff
|
|
246
|
+
: 0x3fffffff
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function createBuffer (that, length) {
|
|
250
|
+
if (kMaxLength() < length) {
|
|
251
|
+
throw new RangeError('Invalid typed array length')
|
|
252
|
+
}
|
|
253
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
254
|
+
// Return an augmented `Uint8Array` instance, for best performance
|
|
255
|
+
that = new Uint8Array(length);
|
|
256
|
+
that.__proto__ = Buffer.prototype;
|
|
257
|
+
} else {
|
|
258
|
+
// Fallback: Return an object instance of the Buffer class
|
|
259
|
+
if (that === null) {
|
|
260
|
+
that = new Buffer(length);
|
|
261
|
+
}
|
|
262
|
+
that.length = length;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return that
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
270
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
271
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
272
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
273
|
+
* returns a single octet.
|
|
274
|
+
*
|
|
275
|
+
* The `Uint8Array` prototype remains unmodified.
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
function Buffer (arg, encodingOrOffset, length) {
|
|
279
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
|
|
280
|
+
return new Buffer(arg, encodingOrOffset, length)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Common case.
|
|
284
|
+
if (typeof arg === 'number') {
|
|
285
|
+
if (typeof encodingOrOffset === 'string') {
|
|
286
|
+
throw new Error(
|
|
287
|
+
'If encoding is specified then the first argument must be a string'
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
return allocUnsafe(this, arg)
|
|
291
|
+
}
|
|
292
|
+
return from(this, arg, encodingOrOffset, length)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
Buffer.poolSize = 8192; // not used by this implementation
|
|
296
|
+
|
|
297
|
+
// TODO: Legacy, not needed anymore. Remove in next major version.
|
|
298
|
+
Buffer._augment = function (arr) {
|
|
299
|
+
arr.__proto__ = Buffer.prototype;
|
|
300
|
+
return arr
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
function from (that, value, encodingOrOffset, length) {
|
|
304
|
+
if (typeof value === 'number') {
|
|
305
|
+
throw new TypeError('"value" argument must not be a number')
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
|
|
309
|
+
return fromArrayBuffer(that, value, encodingOrOffset, length)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (typeof value === 'string') {
|
|
313
|
+
return fromString(that, value, encodingOrOffset)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return fromObject(that, value)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
321
|
+
* if value is a number.
|
|
322
|
+
* Buffer.from(str[, encoding])
|
|
323
|
+
* Buffer.from(array)
|
|
324
|
+
* Buffer.from(buffer)
|
|
325
|
+
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
326
|
+
**/
|
|
327
|
+
Buffer.from = function (value, encodingOrOffset, length) {
|
|
328
|
+
return from(null, value, encodingOrOffset, length)
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
332
|
+
Buffer.prototype.__proto__ = Uint8Array.prototype;
|
|
333
|
+
Buffer.__proto__ = Uint8Array;
|
|
334
|
+
if (typeof Symbol !== 'undefined' && Symbol.species &&
|
|
335
|
+
Buffer[Symbol.species] === Buffer) ;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function assertSize (size) {
|
|
339
|
+
if (typeof size !== 'number') {
|
|
340
|
+
throw new TypeError('"size" argument must be a number')
|
|
341
|
+
} else if (size < 0) {
|
|
342
|
+
throw new RangeError('"size" argument must not be negative')
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function alloc (that, size, fill, encoding) {
|
|
347
|
+
assertSize(size);
|
|
348
|
+
if (size <= 0) {
|
|
349
|
+
return createBuffer(that, size)
|
|
350
|
+
}
|
|
351
|
+
if (fill !== undefined) {
|
|
352
|
+
// Only pay attention to encoding if it's a string. This
|
|
353
|
+
// prevents accidentally sending in a number that would
|
|
354
|
+
// be interpretted as a start offset.
|
|
355
|
+
return typeof encoding === 'string'
|
|
356
|
+
? createBuffer(that, size).fill(fill, encoding)
|
|
357
|
+
: createBuffer(that, size).fill(fill)
|
|
358
|
+
}
|
|
359
|
+
return createBuffer(that, size)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Creates a new filled Buffer instance.
|
|
364
|
+
* alloc(size[, fill[, encoding]])
|
|
365
|
+
**/
|
|
366
|
+
Buffer.alloc = function (size, fill, encoding) {
|
|
367
|
+
return alloc(null, size, fill, encoding)
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
function allocUnsafe (that, size) {
|
|
371
|
+
assertSize(size);
|
|
372
|
+
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
|
|
373
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) {
|
|
374
|
+
for (var i = 0; i < size; ++i) {
|
|
375
|
+
that[i] = 0;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return that
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
383
|
+
* */
|
|
384
|
+
Buffer.allocUnsafe = function (size) {
|
|
385
|
+
return allocUnsafe(null, size)
|
|
386
|
+
};
|
|
387
|
+
/**
|
|
388
|
+
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
389
|
+
*/
|
|
390
|
+
Buffer.allocUnsafeSlow = function (size) {
|
|
391
|
+
return allocUnsafe(null, size)
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
function fromString (that, string, encoding) {
|
|
395
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
|
396
|
+
encoding = 'utf8';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
400
|
+
throw new TypeError('"encoding" must be a valid string encoding')
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
var length = byteLength(string, encoding) | 0;
|
|
404
|
+
that = createBuffer(that, length);
|
|
405
|
+
|
|
406
|
+
var actual = that.write(string, encoding);
|
|
407
|
+
|
|
408
|
+
if (actual !== length) {
|
|
409
|
+
// Writing a hex string, for example, that contains invalid characters will
|
|
410
|
+
// cause everything after the first invalid character to be ignored. (e.g.
|
|
411
|
+
// 'abxxcd' will be treated as 'ab')
|
|
412
|
+
that = that.slice(0, actual);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return that
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function fromArrayLike (that, array) {
|
|
419
|
+
var length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
420
|
+
that = createBuffer(that, length);
|
|
421
|
+
for (var i = 0; i < length; i += 1) {
|
|
422
|
+
that[i] = array[i] & 255;
|
|
423
|
+
}
|
|
424
|
+
return that
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function fromArrayBuffer (that, array, byteOffset, length) {
|
|
428
|
+
array.byteLength; // this throws if `array` is not a valid ArrayBuffer
|
|
429
|
+
|
|
430
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
431
|
+
throw new RangeError('\'offset\' is out of bounds')
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
435
|
+
throw new RangeError('\'length\' is out of bounds')
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (byteOffset === undefined && length === undefined) {
|
|
439
|
+
array = new Uint8Array(array);
|
|
440
|
+
} else if (length === undefined) {
|
|
441
|
+
array = new Uint8Array(array, byteOffset);
|
|
442
|
+
} else {
|
|
443
|
+
array = new Uint8Array(array, byteOffset, length);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
447
|
+
// Return an augmented `Uint8Array` instance, for best performance
|
|
448
|
+
that = array;
|
|
449
|
+
that.__proto__ = Buffer.prototype;
|
|
450
|
+
} else {
|
|
451
|
+
// Fallback: Return an object instance of the Buffer class
|
|
452
|
+
that = fromArrayLike(that, array);
|
|
453
|
+
}
|
|
454
|
+
return that
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function fromObject (that, obj) {
|
|
458
|
+
if (internalIsBuffer(obj)) {
|
|
459
|
+
var len = checked(obj.length) | 0;
|
|
460
|
+
that = createBuffer(that, len);
|
|
461
|
+
|
|
462
|
+
if (that.length === 0) {
|
|
463
|
+
return that
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
obj.copy(that, 0, 0, len);
|
|
467
|
+
return that
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (obj) {
|
|
471
|
+
if ((typeof ArrayBuffer !== 'undefined' &&
|
|
472
|
+
obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
|
|
473
|
+
if (typeof obj.length !== 'number' || isnan(obj.length)) {
|
|
474
|
+
return createBuffer(that, 0)
|
|
475
|
+
}
|
|
476
|
+
return fromArrayLike(that, obj)
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (obj.type === 'Buffer' && isArray(obj.data)) {
|
|
480
|
+
return fromArrayLike(that, obj.data)
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function checked (length) {
|
|
488
|
+
// Note: cannot use `length < kMaxLength()` here because that fails when
|
|
489
|
+
// length is NaN (which is otherwise coerced to zero.)
|
|
490
|
+
if (length >= kMaxLength()) {
|
|
491
|
+
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
492
|
+
'size: 0x' + kMaxLength().toString(16) + ' bytes')
|
|
493
|
+
}
|
|
494
|
+
return length | 0
|
|
495
|
+
}
|
|
496
|
+
Buffer.isBuffer = isBuffer;
|
|
497
|
+
function internalIsBuffer (b) {
|
|
498
|
+
return !!(b != null && b._isBuffer)
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
Buffer.compare = function compare (a, b) {
|
|
502
|
+
if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
|
|
503
|
+
throw new TypeError('Arguments must be Buffers')
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (a === b) return 0
|
|
507
|
+
|
|
508
|
+
var x = a.length;
|
|
509
|
+
var y = b.length;
|
|
510
|
+
|
|
511
|
+
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
512
|
+
if (a[i] !== b[i]) {
|
|
513
|
+
x = a[i];
|
|
514
|
+
y = b[i];
|
|
515
|
+
break
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (x < y) return -1
|
|
520
|
+
if (y < x) return 1
|
|
521
|
+
return 0
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
Buffer.isEncoding = function isEncoding (encoding) {
|
|
525
|
+
switch (String(encoding).toLowerCase()) {
|
|
526
|
+
case 'hex':
|
|
527
|
+
case 'utf8':
|
|
528
|
+
case 'utf-8':
|
|
529
|
+
case 'ascii':
|
|
530
|
+
case 'latin1':
|
|
531
|
+
case 'binary':
|
|
532
|
+
case 'base64':
|
|
533
|
+
case 'ucs2':
|
|
534
|
+
case 'ucs-2':
|
|
535
|
+
case 'utf16le':
|
|
536
|
+
case 'utf-16le':
|
|
537
|
+
return true
|
|
538
|
+
default:
|
|
539
|
+
return false
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
Buffer.concat = function concat (list, length) {
|
|
544
|
+
if (!isArray(list)) {
|
|
545
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (list.length === 0) {
|
|
549
|
+
return Buffer.alloc(0)
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
var i;
|
|
553
|
+
if (length === undefined) {
|
|
554
|
+
length = 0;
|
|
555
|
+
for (i = 0; i < list.length; ++i) {
|
|
556
|
+
length += list[i].length;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
var buffer = Buffer.allocUnsafe(length);
|
|
561
|
+
var pos = 0;
|
|
562
|
+
for (i = 0; i < list.length; ++i) {
|
|
563
|
+
var buf = list[i];
|
|
564
|
+
if (!internalIsBuffer(buf)) {
|
|
565
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
566
|
+
}
|
|
567
|
+
buf.copy(buffer, pos);
|
|
568
|
+
pos += buf.length;
|
|
569
|
+
}
|
|
570
|
+
return buffer
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
function byteLength (string, encoding) {
|
|
574
|
+
if (internalIsBuffer(string)) {
|
|
575
|
+
return string.length
|
|
576
|
+
}
|
|
577
|
+
if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
|
|
578
|
+
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
|
|
579
|
+
return string.byteLength
|
|
580
|
+
}
|
|
581
|
+
if (typeof string !== 'string') {
|
|
582
|
+
string = '' + string;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
var len = string.length;
|
|
586
|
+
if (len === 0) return 0
|
|
587
|
+
|
|
588
|
+
// Use a for loop to avoid recursion
|
|
589
|
+
var loweredCase = false;
|
|
590
|
+
for (;;) {
|
|
591
|
+
switch (encoding) {
|
|
592
|
+
case 'ascii':
|
|
593
|
+
case 'latin1':
|
|
594
|
+
case 'binary':
|
|
595
|
+
return len
|
|
596
|
+
case 'utf8':
|
|
597
|
+
case 'utf-8':
|
|
598
|
+
case undefined:
|
|
599
|
+
return utf8ToBytes(string).length
|
|
600
|
+
case 'ucs2':
|
|
601
|
+
case 'ucs-2':
|
|
602
|
+
case 'utf16le':
|
|
603
|
+
case 'utf-16le':
|
|
604
|
+
return len * 2
|
|
605
|
+
case 'hex':
|
|
606
|
+
return len >>> 1
|
|
607
|
+
case 'base64':
|
|
608
|
+
return base64ToBytes(string).length
|
|
609
|
+
default:
|
|
610
|
+
if (loweredCase) return utf8ToBytes(string).length // assume utf8
|
|
611
|
+
encoding = ('' + encoding).toLowerCase();
|
|
612
|
+
loweredCase = true;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
Buffer.byteLength = byteLength;
|
|
617
|
+
|
|
618
|
+
function slowToString (encoding, start, end) {
|
|
619
|
+
var loweredCase = false;
|
|
620
|
+
|
|
621
|
+
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
622
|
+
// property of a typed array.
|
|
623
|
+
|
|
624
|
+
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
625
|
+
// to their upper/lower bounds if the value passed is out of range.
|
|
626
|
+
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
627
|
+
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
628
|
+
if (start === undefined || start < 0) {
|
|
629
|
+
start = 0;
|
|
630
|
+
}
|
|
631
|
+
// Return early if start > this.length. Done here to prevent potential uint32
|
|
632
|
+
// coercion fail below.
|
|
633
|
+
if (start > this.length) {
|
|
634
|
+
return ''
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (end === undefined || end > this.length) {
|
|
638
|
+
end = this.length;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (end <= 0) {
|
|
642
|
+
return ''
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
|
|
646
|
+
end >>>= 0;
|
|
647
|
+
start >>>= 0;
|
|
648
|
+
|
|
649
|
+
if (end <= start) {
|
|
650
|
+
return ''
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if (!encoding) encoding = 'utf8';
|
|
654
|
+
|
|
655
|
+
while (true) {
|
|
656
|
+
switch (encoding) {
|
|
657
|
+
case 'hex':
|
|
658
|
+
return hexSlice(this, start, end)
|
|
659
|
+
|
|
660
|
+
case 'utf8':
|
|
661
|
+
case 'utf-8':
|
|
662
|
+
return utf8Slice(this, start, end)
|
|
663
|
+
|
|
664
|
+
case 'ascii':
|
|
665
|
+
return asciiSlice(this, start, end)
|
|
666
|
+
|
|
667
|
+
case 'latin1':
|
|
668
|
+
case 'binary':
|
|
669
|
+
return latin1Slice(this, start, end)
|
|
670
|
+
|
|
671
|
+
case 'base64':
|
|
672
|
+
return base64Slice(this, start, end)
|
|
673
|
+
|
|
674
|
+
case 'ucs2':
|
|
675
|
+
case 'ucs-2':
|
|
676
|
+
case 'utf16le':
|
|
677
|
+
case 'utf-16le':
|
|
678
|
+
return utf16leSlice(this, start, end)
|
|
679
|
+
|
|
680
|
+
default:
|
|
681
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
682
|
+
encoding = (encoding + '').toLowerCase();
|
|
683
|
+
loweredCase = true;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
|
|
689
|
+
// Buffer instances.
|
|
690
|
+
Buffer.prototype._isBuffer = true;
|
|
691
|
+
|
|
692
|
+
function swap (b, n, m) {
|
|
693
|
+
var i = b[n];
|
|
694
|
+
b[n] = b[m];
|
|
695
|
+
b[m] = i;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
Buffer.prototype.swap16 = function swap16 () {
|
|
699
|
+
var len = this.length;
|
|
700
|
+
if (len % 2 !== 0) {
|
|
701
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
702
|
+
}
|
|
703
|
+
for (var i = 0; i < len; i += 2) {
|
|
704
|
+
swap(this, i, i + 1);
|
|
705
|
+
}
|
|
706
|
+
return this
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
Buffer.prototype.swap32 = function swap32 () {
|
|
710
|
+
var len = this.length;
|
|
711
|
+
if (len % 4 !== 0) {
|
|
712
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
713
|
+
}
|
|
714
|
+
for (var i = 0; i < len; i += 4) {
|
|
715
|
+
swap(this, i, i + 3);
|
|
716
|
+
swap(this, i + 1, i + 2);
|
|
717
|
+
}
|
|
718
|
+
return this
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
Buffer.prototype.swap64 = function swap64 () {
|
|
722
|
+
var len = this.length;
|
|
723
|
+
if (len % 8 !== 0) {
|
|
724
|
+
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
725
|
+
}
|
|
726
|
+
for (var i = 0; i < len; i += 8) {
|
|
727
|
+
swap(this, i, i + 7);
|
|
728
|
+
swap(this, i + 1, i + 6);
|
|
729
|
+
swap(this, i + 2, i + 5);
|
|
730
|
+
swap(this, i + 3, i + 4);
|
|
731
|
+
}
|
|
732
|
+
return this
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
Buffer.prototype.toString = function toString () {
|
|
736
|
+
var length = this.length | 0;
|
|
737
|
+
if (length === 0) return ''
|
|
738
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
739
|
+
return slowToString.apply(this, arguments)
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
Buffer.prototype.equals = function equals (b) {
|
|
743
|
+
if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
744
|
+
if (this === b) return true
|
|
745
|
+
return Buffer.compare(this, b) === 0
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
Buffer.prototype.inspect = function inspect () {
|
|
749
|
+
var str = '';
|
|
750
|
+
var max = INSPECT_MAX_BYTES;
|
|
751
|
+
if (this.length > 0) {
|
|
752
|
+
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
|
|
753
|
+
if (this.length > max) str += ' ... ';
|
|
754
|
+
}
|
|
755
|
+
return '<Buffer ' + str + '>'
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
759
|
+
if (!internalIsBuffer(target)) {
|
|
760
|
+
throw new TypeError('Argument must be a Buffer')
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
if (start === undefined) {
|
|
764
|
+
start = 0;
|
|
765
|
+
}
|
|
766
|
+
if (end === undefined) {
|
|
767
|
+
end = target ? target.length : 0;
|
|
768
|
+
}
|
|
769
|
+
if (thisStart === undefined) {
|
|
770
|
+
thisStart = 0;
|
|
771
|
+
}
|
|
772
|
+
if (thisEnd === undefined) {
|
|
773
|
+
thisEnd = this.length;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
777
|
+
throw new RangeError('out of range index')
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
781
|
+
return 0
|
|
782
|
+
}
|
|
783
|
+
if (thisStart >= thisEnd) {
|
|
784
|
+
return -1
|
|
785
|
+
}
|
|
786
|
+
if (start >= end) {
|
|
787
|
+
return 1
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
start >>>= 0;
|
|
791
|
+
end >>>= 0;
|
|
792
|
+
thisStart >>>= 0;
|
|
793
|
+
thisEnd >>>= 0;
|
|
794
|
+
|
|
795
|
+
if (this === target) return 0
|
|
796
|
+
|
|
797
|
+
var x = thisEnd - thisStart;
|
|
798
|
+
var y = end - start;
|
|
799
|
+
var len = Math.min(x, y);
|
|
800
|
+
|
|
801
|
+
var thisCopy = this.slice(thisStart, thisEnd);
|
|
802
|
+
var targetCopy = target.slice(start, end);
|
|
803
|
+
|
|
804
|
+
for (var i = 0; i < len; ++i) {
|
|
805
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
806
|
+
x = thisCopy[i];
|
|
807
|
+
y = targetCopy[i];
|
|
808
|
+
break
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
if (x < y) return -1
|
|
813
|
+
if (y < x) return 1
|
|
814
|
+
return 0
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
818
|
+
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
819
|
+
//
|
|
820
|
+
// Arguments:
|
|
821
|
+
// - buffer - a Buffer to search
|
|
822
|
+
// - val - a string, Buffer, or number
|
|
823
|
+
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
824
|
+
// - encoding - an optional encoding, relevant is val is a string
|
|
825
|
+
// - dir - true for indexOf, false for lastIndexOf
|
|
826
|
+
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
827
|
+
// Empty buffer means no match
|
|
828
|
+
if (buffer.length === 0) return -1
|
|
829
|
+
|
|
830
|
+
// Normalize byteOffset
|
|
831
|
+
if (typeof byteOffset === 'string') {
|
|
832
|
+
encoding = byteOffset;
|
|
833
|
+
byteOffset = 0;
|
|
834
|
+
} else if (byteOffset > 0x7fffffff) {
|
|
835
|
+
byteOffset = 0x7fffffff;
|
|
836
|
+
} else if (byteOffset < -2147483648) {
|
|
837
|
+
byteOffset = -2147483648;
|
|
838
|
+
}
|
|
839
|
+
byteOffset = +byteOffset; // Coerce to Number.
|
|
840
|
+
if (isNaN(byteOffset)) {
|
|
841
|
+
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
842
|
+
byteOffset = dir ? 0 : (buffer.length - 1);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
846
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
847
|
+
if (byteOffset >= buffer.length) {
|
|
848
|
+
if (dir) return -1
|
|
849
|
+
else byteOffset = buffer.length - 1;
|
|
850
|
+
} else if (byteOffset < 0) {
|
|
851
|
+
if (dir) byteOffset = 0;
|
|
852
|
+
else return -1
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// Normalize val
|
|
856
|
+
if (typeof val === 'string') {
|
|
857
|
+
val = Buffer.from(val, encoding);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
861
|
+
if (internalIsBuffer(val)) {
|
|
862
|
+
// Special case: looking for empty string/buffer always fails
|
|
863
|
+
if (val.length === 0) {
|
|
864
|
+
return -1
|
|
865
|
+
}
|
|
866
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
867
|
+
} else if (typeof val === 'number') {
|
|
868
|
+
val = val & 0xFF; // Search for a byte value [0-255]
|
|
869
|
+
if (Buffer.TYPED_ARRAY_SUPPORT &&
|
|
870
|
+
typeof Uint8Array.prototype.indexOf === 'function') {
|
|
871
|
+
if (dir) {
|
|
872
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
873
|
+
} else {
|
|
874
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
throw new TypeError('val must be string, number or Buffer')
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
884
|
+
var indexSize = 1;
|
|
885
|
+
var arrLength = arr.length;
|
|
886
|
+
var valLength = val.length;
|
|
887
|
+
|
|
888
|
+
if (encoding !== undefined) {
|
|
889
|
+
encoding = String(encoding).toLowerCase();
|
|
890
|
+
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
891
|
+
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
892
|
+
if (arr.length < 2 || val.length < 2) {
|
|
893
|
+
return -1
|
|
894
|
+
}
|
|
895
|
+
indexSize = 2;
|
|
896
|
+
arrLength /= 2;
|
|
897
|
+
valLength /= 2;
|
|
898
|
+
byteOffset /= 2;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
function read (buf, i) {
|
|
903
|
+
if (indexSize === 1) {
|
|
904
|
+
return buf[i]
|
|
905
|
+
} else {
|
|
906
|
+
return buf.readUInt16BE(i * indexSize)
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
var i;
|
|
911
|
+
if (dir) {
|
|
912
|
+
var foundIndex = -1;
|
|
913
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
914
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
915
|
+
if (foundIndex === -1) foundIndex = i;
|
|
916
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
917
|
+
} else {
|
|
918
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
919
|
+
foundIndex = -1;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
} else {
|
|
923
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
924
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
925
|
+
var found = true;
|
|
926
|
+
for (var j = 0; j < valLength; j++) {
|
|
927
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
928
|
+
found = false;
|
|
929
|
+
break
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
if (found) return i
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
return -1
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
940
|
+
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
944
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
948
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
function hexWrite (buf, string, offset, length) {
|
|
952
|
+
offset = Number(offset) || 0;
|
|
953
|
+
var remaining = buf.length - offset;
|
|
954
|
+
if (!length) {
|
|
955
|
+
length = remaining;
|
|
956
|
+
} else {
|
|
957
|
+
length = Number(length);
|
|
958
|
+
if (length > remaining) {
|
|
959
|
+
length = remaining;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// must be an even number of digits
|
|
964
|
+
var strLen = string.length;
|
|
965
|
+
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
|
|
966
|
+
|
|
967
|
+
if (length > strLen / 2) {
|
|
968
|
+
length = strLen / 2;
|
|
969
|
+
}
|
|
970
|
+
for (var i = 0; i < length; ++i) {
|
|
971
|
+
var parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
972
|
+
if (isNaN(parsed)) return i
|
|
973
|
+
buf[offset + i] = parsed;
|
|
974
|
+
}
|
|
975
|
+
return i
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function utf8Write (buf, string, offset, length) {
|
|
979
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
function asciiWrite (buf, string, offset, length) {
|
|
983
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
function latin1Write (buf, string, offset, length) {
|
|
987
|
+
return asciiWrite(buf, string, offset, length)
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
function base64Write (buf, string, offset, length) {
|
|
991
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function ucs2Write (buf, string, offset, length) {
|
|
995
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
999
|
+
// Buffer#write(string)
|
|
1000
|
+
if (offset === undefined) {
|
|
1001
|
+
encoding = 'utf8';
|
|
1002
|
+
length = this.length;
|
|
1003
|
+
offset = 0;
|
|
1004
|
+
// Buffer#write(string, encoding)
|
|
1005
|
+
} else if (length === undefined && typeof offset === 'string') {
|
|
1006
|
+
encoding = offset;
|
|
1007
|
+
length = this.length;
|
|
1008
|
+
offset = 0;
|
|
1009
|
+
// Buffer#write(string, offset[, length][, encoding])
|
|
1010
|
+
} else if (isFinite(offset)) {
|
|
1011
|
+
offset = offset | 0;
|
|
1012
|
+
if (isFinite(length)) {
|
|
1013
|
+
length = length | 0;
|
|
1014
|
+
if (encoding === undefined) encoding = 'utf8';
|
|
1015
|
+
} else {
|
|
1016
|
+
encoding = length;
|
|
1017
|
+
length = undefined;
|
|
1018
|
+
}
|
|
1019
|
+
// legacy write(string, encoding, offset, length) - remove in v0.13
|
|
1020
|
+
} else {
|
|
1021
|
+
throw new Error(
|
|
1022
|
+
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
1023
|
+
)
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
var remaining = this.length - offset;
|
|
1027
|
+
if (length === undefined || length > remaining) length = remaining;
|
|
1028
|
+
|
|
1029
|
+
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
1030
|
+
throw new RangeError('Attempt to write outside buffer bounds')
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
if (!encoding) encoding = 'utf8';
|
|
1034
|
+
|
|
1035
|
+
var loweredCase = false;
|
|
1036
|
+
for (;;) {
|
|
1037
|
+
switch (encoding) {
|
|
1038
|
+
case 'hex':
|
|
1039
|
+
return hexWrite(this, string, offset, length)
|
|
1040
|
+
|
|
1041
|
+
case 'utf8':
|
|
1042
|
+
case 'utf-8':
|
|
1043
|
+
return utf8Write(this, string, offset, length)
|
|
1044
|
+
|
|
1045
|
+
case 'ascii':
|
|
1046
|
+
return asciiWrite(this, string, offset, length)
|
|
1047
|
+
|
|
1048
|
+
case 'latin1':
|
|
1049
|
+
case 'binary':
|
|
1050
|
+
return latin1Write(this, string, offset, length)
|
|
1051
|
+
|
|
1052
|
+
case 'base64':
|
|
1053
|
+
// Warning: maxLength not taken into account in base64Write
|
|
1054
|
+
return base64Write(this, string, offset, length)
|
|
1055
|
+
|
|
1056
|
+
case 'ucs2':
|
|
1057
|
+
case 'ucs-2':
|
|
1058
|
+
case 'utf16le':
|
|
1059
|
+
case 'utf-16le':
|
|
1060
|
+
return ucs2Write(this, string, offset, length)
|
|
1061
|
+
|
|
1062
|
+
default:
|
|
1063
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
1064
|
+
encoding = ('' + encoding).toLowerCase();
|
|
1065
|
+
loweredCase = true;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
Buffer.prototype.toJSON = function toJSON () {
|
|
1071
|
+
return {
|
|
1072
|
+
type: 'Buffer',
|
|
1073
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
function base64Slice (buf, start, end) {
|
|
1078
|
+
if (start === 0 && end === buf.length) {
|
|
1079
|
+
return fromByteArray(buf)
|
|
1080
|
+
} else {
|
|
1081
|
+
return fromByteArray(buf.slice(start, end))
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
function utf8Slice (buf, start, end) {
|
|
1086
|
+
end = Math.min(buf.length, end);
|
|
1087
|
+
var res = [];
|
|
1088
|
+
|
|
1089
|
+
var i = start;
|
|
1090
|
+
while (i < end) {
|
|
1091
|
+
var firstByte = buf[i];
|
|
1092
|
+
var codePoint = null;
|
|
1093
|
+
var bytesPerSequence = (firstByte > 0xEF) ? 4
|
|
1094
|
+
: (firstByte > 0xDF) ? 3
|
|
1095
|
+
: (firstByte > 0xBF) ? 2
|
|
1096
|
+
: 1;
|
|
1097
|
+
|
|
1098
|
+
if (i + bytesPerSequence <= end) {
|
|
1099
|
+
var secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
1100
|
+
|
|
1101
|
+
switch (bytesPerSequence) {
|
|
1102
|
+
case 1:
|
|
1103
|
+
if (firstByte < 0x80) {
|
|
1104
|
+
codePoint = firstByte;
|
|
1105
|
+
}
|
|
1106
|
+
break
|
|
1107
|
+
case 2:
|
|
1108
|
+
secondByte = buf[i + 1];
|
|
1109
|
+
if ((secondByte & 0xC0) === 0x80) {
|
|
1110
|
+
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
|
|
1111
|
+
if (tempCodePoint > 0x7F) {
|
|
1112
|
+
codePoint = tempCodePoint;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
break
|
|
1116
|
+
case 3:
|
|
1117
|
+
secondByte = buf[i + 1];
|
|
1118
|
+
thirdByte = buf[i + 2];
|
|
1119
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
1120
|
+
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
|
1121
|
+
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
1122
|
+
codePoint = tempCodePoint;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
break
|
|
1126
|
+
case 4:
|
|
1127
|
+
secondByte = buf[i + 1];
|
|
1128
|
+
thirdByte = buf[i + 2];
|
|
1129
|
+
fourthByte = buf[i + 3];
|
|
1130
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
1131
|
+
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
|
|
1132
|
+
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
1133
|
+
codePoint = tempCodePoint;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
if (codePoint === null) {
|
|
1140
|
+
// we did not generate a valid codePoint so insert a
|
|
1141
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
1142
|
+
codePoint = 0xFFFD;
|
|
1143
|
+
bytesPerSequence = 1;
|
|
1144
|
+
} else if (codePoint > 0xFFFF) {
|
|
1145
|
+
// encode to utf16 (surrogate pair dance)
|
|
1146
|
+
codePoint -= 0x10000;
|
|
1147
|
+
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
|
1148
|
+
codePoint = 0xDC00 | codePoint & 0x3FF;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
res.push(codePoint);
|
|
1152
|
+
i += bytesPerSequence;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
return decodeCodePointsArray(res)
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
1159
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
|
1160
|
+
// We go 1 magnitude less, for safety
|
|
1161
|
+
var MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
1162
|
+
|
|
1163
|
+
function decodeCodePointsArray (codePoints) {
|
|
1164
|
+
var len = codePoints.length;
|
|
1165
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1166
|
+
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
|
1170
|
+
var res = '';
|
|
1171
|
+
var i = 0;
|
|
1172
|
+
while (i < len) {
|
|
1173
|
+
res += String.fromCharCode.apply(
|
|
1174
|
+
String,
|
|
1175
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
1176
|
+
);
|
|
1177
|
+
}
|
|
1178
|
+
return res
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
function asciiSlice (buf, start, end) {
|
|
1182
|
+
var ret = '';
|
|
1183
|
+
end = Math.min(buf.length, end);
|
|
1184
|
+
|
|
1185
|
+
for (var i = start; i < end; ++i) {
|
|
1186
|
+
ret += String.fromCharCode(buf[i] & 0x7F);
|
|
1187
|
+
}
|
|
1188
|
+
return ret
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
function latin1Slice (buf, start, end) {
|
|
1192
|
+
var ret = '';
|
|
1193
|
+
end = Math.min(buf.length, end);
|
|
1194
|
+
|
|
1195
|
+
for (var i = start; i < end; ++i) {
|
|
1196
|
+
ret += String.fromCharCode(buf[i]);
|
|
1197
|
+
}
|
|
1198
|
+
return ret
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
function hexSlice (buf, start, end) {
|
|
1202
|
+
var len = buf.length;
|
|
1203
|
+
|
|
1204
|
+
if (!start || start < 0) start = 0;
|
|
1205
|
+
if (!end || end < 0 || end > len) end = len;
|
|
1206
|
+
|
|
1207
|
+
var out = '';
|
|
1208
|
+
for (var i = start; i < end; ++i) {
|
|
1209
|
+
out += toHex(buf[i]);
|
|
1210
|
+
}
|
|
1211
|
+
return out
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
function utf16leSlice (buf, start, end) {
|
|
1215
|
+
var bytes = buf.slice(start, end);
|
|
1216
|
+
var res = '';
|
|
1217
|
+
for (var i = 0; i < bytes.length; i += 2) {
|
|
1218
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1219
|
+
}
|
|
1220
|
+
return res
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
Buffer.prototype.slice = function slice (start, end) {
|
|
1224
|
+
var len = this.length;
|
|
1225
|
+
start = ~~start;
|
|
1226
|
+
end = end === undefined ? len : ~~end;
|
|
1227
|
+
|
|
1228
|
+
if (start < 0) {
|
|
1229
|
+
start += len;
|
|
1230
|
+
if (start < 0) start = 0;
|
|
1231
|
+
} else if (start > len) {
|
|
1232
|
+
start = len;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
if (end < 0) {
|
|
1236
|
+
end += len;
|
|
1237
|
+
if (end < 0) end = 0;
|
|
1238
|
+
} else if (end > len) {
|
|
1239
|
+
end = len;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
if (end < start) end = start;
|
|
1243
|
+
|
|
1244
|
+
var newBuf;
|
|
1245
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1246
|
+
newBuf = this.subarray(start, end);
|
|
1247
|
+
newBuf.__proto__ = Buffer.prototype;
|
|
1248
|
+
} else {
|
|
1249
|
+
var sliceLen = end - start;
|
|
1250
|
+
newBuf = new Buffer(sliceLen, undefined);
|
|
1251
|
+
for (var i = 0; i < sliceLen; ++i) {
|
|
1252
|
+
newBuf[i] = this[i + start];
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
return newBuf
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
/*
|
|
1260
|
+
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
1261
|
+
*/
|
|
1262
|
+
function checkOffset (offset, ext, length) {
|
|
1263
|
+
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
1264
|
+
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
1268
|
+
offset = offset | 0;
|
|
1269
|
+
byteLength = byteLength | 0;
|
|
1270
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1271
|
+
|
|
1272
|
+
var val = this[offset];
|
|
1273
|
+
var mul = 1;
|
|
1274
|
+
var i = 0;
|
|
1275
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1276
|
+
val += this[offset + i] * mul;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
return val
|
|
1280
|
+
};
|
|
1281
|
+
|
|
1282
|
+
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
1283
|
+
offset = offset | 0;
|
|
1284
|
+
byteLength = byteLength | 0;
|
|
1285
|
+
if (!noAssert) {
|
|
1286
|
+
checkOffset(offset, byteLength, this.length);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
var val = this[offset + --byteLength];
|
|
1290
|
+
var mul = 1;
|
|
1291
|
+
while (byteLength > 0 && (mul *= 0x100)) {
|
|
1292
|
+
val += this[offset + --byteLength] * mul;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
return val
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
1299
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1300
|
+
return this[offset]
|
|
1301
|
+
};
|
|
1302
|
+
|
|
1303
|
+
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
1304
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1305
|
+
return this[offset] | (this[offset + 1] << 8)
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
1309
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1310
|
+
return (this[offset] << 8) | this[offset + 1]
|
|
1311
|
+
};
|
|
1312
|
+
|
|
1313
|
+
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
1314
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1315
|
+
|
|
1316
|
+
return ((this[offset]) |
|
|
1317
|
+
(this[offset + 1] << 8) |
|
|
1318
|
+
(this[offset + 2] << 16)) +
|
|
1319
|
+
(this[offset + 3] * 0x1000000)
|
|
1320
|
+
};
|
|
1321
|
+
|
|
1322
|
+
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
1323
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1324
|
+
|
|
1325
|
+
return (this[offset] * 0x1000000) +
|
|
1326
|
+
((this[offset + 1] << 16) |
|
|
1327
|
+
(this[offset + 2] << 8) |
|
|
1328
|
+
this[offset + 3])
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
1332
|
+
offset = offset | 0;
|
|
1333
|
+
byteLength = byteLength | 0;
|
|
1334
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1335
|
+
|
|
1336
|
+
var val = this[offset];
|
|
1337
|
+
var mul = 1;
|
|
1338
|
+
var i = 0;
|
|
1339
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1340
|
+
val += this[offset + i] * mul;
|
|
1341
|
+
}
|
|
1342
|
+
mul *= 0x80;
|
|
1343
|
+
|
|
1344
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
1345
|
+
|
|
1346
|
+
return val
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
1350
|
+
offset = offset | 0;
|
|
1351
|
+
byteLength = byteLength | 0;
|
|
1352
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1353
|
+
|
|
1354
|
+
var i = byteLength;
|
|
1355
|
+
var mul = 1;
|
|
1356
|
+
var val = this[offset + --i];
|
|
1357
|
+
while (i > 0 && (mul *= 0x100)) {
|
|
1358
|
+
val += this[offset + --i] * mul;
|
|
1359
|
+
}
|
|
1360
|
+
mul *= 0x80;
|
|
1361
|
+
|
|
1362
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
1363
|
+
|
|
1364
|
+
return val
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1367
|
+
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
1368
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1369
|
+
if (!(this[offset] & 0x80)) return (this[offset])
|
|
1370
|
+
return ((0xff - this[offset] + 1) * -1)
|
|
1371
|
+
};
|
|
1372
|
+
|
|
1373
|
+
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
1374
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1375
|
+
var val = this[offset] | (this[offset + 1] << 8);
|
|
1376
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1377
|
+
};
|
|
1378
|
+
|
|
1379
|
+
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
1380
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1381
|
+
var val = this[offset + 1] | (this[offset] << 8);
|
|
1382
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
1386
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1387
|
+
|
|
1388
|
+
return (this[offset]) |
|
|
1389
|
+
(this[offset + 1] << 8) |
|
|
1390
|
+
(this[offset + 2] << 16) |
|
|
1391
|
+
(this[offset + 3] << 24)
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
1395
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1396
|
+
|
|
1397
|
+
return (this[offset] << 24) |
|
|
1398
|
+
(this[offset + 1] << 16) |
|
|
1399
|
+
(this[offset + 2] << 8) |
|
|
1400
|
+
(this[offset + 3])
|
|
1401
|
+
};
|
|
1402
|
+
|
|
1403
|
+
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
1404
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1405
|
+
return read(this, offset, true, 23, 4)
|
|
1406
|
+
};
|
|
1407
|
+
|
|
1408
|
+
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
1409
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1410
|
+
return read(this, offset, false, 23, 4)
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
1414
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1415
|
+
return read(this, offset, true, 52, 8)
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
1419
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1420
|
+
return read(this, offset, false, 52, 8)
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
function checkInt (buf, value, offset, ext, max, min) {
|
|
1424
|
+
if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
1425
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
1426
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
1430
|
+
value = +value;
|
|
1431
|
+
offset = offset | 0;
|
|
1432
|
+
byteLength = byteLength | 0;
|
|
1433
|
+
if (!noAssert) {
|
|
1434
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
1435
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
var mul = 1;
|
|
1439
|
+
var i = 0;
|
|
1440
|
+
this[offset] = value & 0xFF;
|
|
1441
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1442
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
return offset + byteLength
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1448
|
+
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
1449
|
+
value = +value;
|
|
1450
|
+
offset = offset | 0;
|
|
1451
|
+
byteLength = byteLength | 0;
|
|
1452
|
+
if (!noAssert) {
|
|
1453
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
1454
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
var i = byteLength - 1;
|
|
1458
|
+
var mul = 1;
|
|
1459
|
+
this[offset + i] = value & 0xFF;
|
|
1460
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
1461
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
return offset + byteLength
|
|
1465
|
+
};
|
|
1466
|
+
|
|
1467
|
+
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
1468
|
+
value = +value;
|
|
1469
|
+
offset = offset | 0;
|
|
1470
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
1471
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
1472
|
+
this[offset] = (value & 0xff);
|
|
1473
|
+
return offset + 1
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
function objectWriteUInt16 (buf, value, offset, littleEndian) {
|
|
1477
|
+
if (value < 0) value = 0xffff + value + 1;
|
|
1478
|
+
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
|
|
1479
|
+
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
|
|
1480
|
+
(littleEndian ? i : 1 - i) * 8;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
1485
|
+
value = +value;
|
|
1486
|
+
offset = offset | 0;
|
|
1487
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
1488
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1489
|
+
this[offset] = (value & 0xff);
|
|
1490
|
+
this[offset + 1] = (value >>> 8);
|
|
1491
|
+
} else {
|
|
1492
|
+
objectWriteUInt16(this, value, offset, true);
|
|
1493
|
+
}
|
|
1494
|
+
return offset + 2
|
|
1495
|
+
};
|
|
1496
|
+
|
|
1497
|
+
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
1498
|
+
value = +value;
|
|
1499
|
+
offset = offset | 0;
|
|
1500
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
1501
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1502
|
+
this[offset] = (value >>> 8);
|
|
1503
|
+
this[offset + 1] = (value & 0xff);
|
|
1504
|
+
} else {
|
|
1505
|
+
objectWriteUInt16(this, value, offset, false);
|
|
1506
|
+
}
|
|
1507
|
+
return offset + 2
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
function objectWriteUInt32 (buf, value, offset, littleEndian) {
|
|
1511
|
+
if (value < 0) value = 0xffffffff + value + 1;
|
|
1512
|
+
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
|
|
1513
|
+
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
1518
|
+
value = +value;
|
|
1519
|
+
offset = offset | 0;
|
|
1520
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
1521
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1522
|
+
this[offset + 3] = (value >>> 24);
|
|
1523
|
+
this[offset + 2] = (value >>> 16);
|
|
1524
|
+
this[offset + 1] = (value >>> 8);
|
|
1525
|
+
this[offset] = (value & 0xff);
|
|
1526
|
+
} else {
|
|
1527
|
+
objectWriteUInt32(this, value, offset, true);
|
|
1528
|
+
}
|
|
1529
|
+
return offset + 4
|
|
1530
|
+
};
|
|
1531
|
+
|
|
1532
|
+
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
1533
|
+
value = +value;
|
|
1534
|
+
offset = offset | 0;
|
|
1535
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
1536
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1537
|
+
this[offset] = (value >>> 24);
|
|
1538
|
+
this[offset + 1] = (value >>> 16);
|
|
1539
|
+
this[offset + 2] = (value >>> 8);
|
|
1540
|
+
this[offset + 3] = (value & 0xff);
|
|
1541
|
+
} else {
|
|
1542
|
+
objectWriteUInt32(this, value, offset, false);
|
|
1543
|
+
}
|
|
1544
|
+
return offset + 4
|
|
1545
|
+
};
|
|
1546
|
+
|
|
1547
|
+
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
1548
|
+
value = +value;
|
|
1549
|
+
offset = offset | 0;
|
|
1550
|
+
if (!noAssert) {
|
|
1551
|
+
var limit = Math.pow(2, 8 * byteLength - 1);
|
|
1552
|
+
|
|
1553
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
var i = 0;
|
|
1557
|
+
var mul = 1;
|
|
1558
|
+
var sub = 0;
|
|
1559
|
+
this[offset] = value & 0xFF;
|
|
1560
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1561
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1562
|
+
sub = 1;
|
|
1563
|
+
}
|
|
1564
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
return offset + byteLength
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1570
|
+
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
1571
|
+
value = +value;
|
|
1572
|
+
offset = offset | 0;
|
|
1573
|
+
if (!noAssert) {
|
|
1574
|
+
var limit = Math.pow(2, 8 * byteLength - 1);
|
|
1575
|
+
|
|
1576
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
var i = byteLength - 1;
|
|
1580
|
+
var mul = 1;
|
|
1581
|
+
var sub = 0;
|
|
1582
|
+
this[offset + i] = value & 0xFF;
|
|
1583
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
1584
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1585
|
+
sub = 1;
|
|
1586
|
+
}
|
|
1587
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
return offset + byteLength
|
|
1591
|
+
};
|
|
1592
|
+
|
|
1593
|
+
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
1594
|
+
value = +value;
|
|
1595
|
+
offset = offset | 0;
|
|
1596
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
|
|
1597
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
|
1598
|
+
if (value < 0) value = 0xff + value + 1;
|
|
1599
|
+
this[offset] = (value & 0xff);
|
|
1600
|
+
return offset + 1
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
1604
|
+
value = +value;
|
|
1605
|
+
offset = offset | 0;
|
|
1606
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
|
|
1607
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1608
|
+
this[offset] = (value & 0xff);
|
|
1609
|
+
this[offset + 1] = (value >>> 8);
|
|
1610
|
+
} else {
|
|
1611
|
+
objectWriteUInt16(this, value, offset, true);
|
|
1612
|
+
}
|
|
1613
|
+
return offset + 2
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1616
|
+
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
1617
|
+
value = +value;
|
|
1618
|
+
offset = offset | 0;
|
|
1619
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
|
|
1620
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1621
|
+
this[offset] = (value >>> 8);
|
|
1622
|
+
this[offset + 1] = (value & 0xff);
|
|
1623
|
+
} else {
|
|
1624
|
+
objectWriteUInt16(this, value, offset, false);
|
|
1625
|
+
}
|
|
1626
|
+
return offset + 2
|
|
1627
|
+
};
|
|
1628
|
+
|
|
1629
|
+
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
1630
|
+
value = +value;
|
|
1631
|
+
offset = offset | 0;
|
|
1632
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
|
|
1633
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1634
|
+
this[offset] = (value & 0xff);
|
|
1635
|
+
this[offset + 1] = (value >>> 8);
|
|
1636
|
+
this[offset + 2] = (value >>> 16);
|
|
1637
|
+
this[offset + 3] = (value >>> 24);
|
|
1638
|
+
} else {
|
|
1639
|
+
objectWriteUInt32(this, value, offset, true);
|
|
1640
|
+
}
|
|
1641
|
+
return offset + 4
|
|
1642
|
+
};
|
|
1643
|
+
|
|
1644
|
+
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
1645
|
+
value = +value;
|
|
1646
|
+
offset = offset | 0;
|
|
1647
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
|
|
1648
|
+
if (value < 0) value = 0xffffffff + value + 1;
|
|
1649
|
+
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1650
|
+
this[offset] = (value >>> 24);
|
|
1651
|
+
this[offset + 1] = (value >>> 16);
|
|
1652
|
+
this[offset + 2] = (value >>> 8);
|
|
1653
|
+
this[offset + 3] = (value & 0xff);
|
|
1654
|
+
} else {
|
|
1655
|
+
objectWriteUInt32(this, value, offset, false);
|
|
1656
|
+
}
|
|
1657
|
+
return offset + 4
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
1661
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1662
|
+
if (offset < 0) throw new RangeError('Index out of range')
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
1666
|
+
if (!noAssert) {
|
|
1667
|
+
checkIEEE754(buf, value, offset, 4);
|
|
1668
|
+
}
|
|
1669
|
+
write(buf, value, offset, littleEndian, 23, 4);
|
|
1670
|
+
return offset + 4
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
1674
|
+
return writeFloat(this, value, offset, true, noAssert)
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
1678
|
+
return writeFloat(this, value, offset, false, noAssert)
|
|
1679
|
+
};
|
|
1680
|
+
|
|
1681
|
+
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
1682
|
+
if (!noAssert) {
|
|
1683
|
+
checkIEEE754(buf, value, offset, 8);
|
|
1684
|
+
}
|
|
1685
|
+
write(buf, value, offset, littleEndian, 52, 8);
|
|
1686
|
+
return offset + 8
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
1690
|
+
return writeDouble(this, value, offset, true, noAssert)
|
|
1691
|
+
};
|
|
1692
|
+
|
|
1693
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
1694
|
+
return writeDouble(this, value, offset, false, noAssert)
|
|
1695
|
+
};
|
|
1696
|
+
|
|
1697
|
+
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
1698
|
+
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
1699
|
+
if (!start) start = 0;
|
|
1700
|
+
if (!end && end !== 0) end = this.length;
|
|
1701
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
1702
|
+
if (!targetStart) targetStart = 0;
|
|
1703
|
+
if (end > 0 && end < start) end = start;
|
|
1704
|
+
|
|
1705
|
+
// Copy 0 bytes; we're done
|
|
1706
|
+
if (end === start) return 0
|
|
1707
|
+
if (target.length === 0 || this.length === 0) return 0
|
|
1708
|
+
|
|
1709
|
+
// Fatal error conditions
|
|
1710
|
+
if (targetStart < 0) {
|
|
1711
|
+
throw new RangeError('targetStart out of bounds')
|
|
1712
|
+
}
|
|
1713
|
+
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
|
|
1714
|
+
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
1715
|
+
|
|
1716
|
+
// Are we oob?
|
|
1717
|
+
if (end > this.length) end = this.length;
|
|
1718
|
+
if (target.length - targetStart < end - start) {
|
|
1719
|
+
end = target.length - targetStart + start;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
var len = end - start;
|
|
1723
|
+
var i;
|
|
1724
|
+
|
|
1725
|
+
if (this === target && start < targetStart && targetStart < end) {
|
|
1726
|
+
// descending copy from end
|
|
1727
|
+
for (i = len - 1; i >= 0; --i) {
|
|
1728
|
+
target[i + targetStart] = this[i + start];
|
|
1729
|
+
}
|
|
1730
|
+
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
|
|
1731
|
+
// ascending copy from start
|
|
1732
|
+
for (i = 0; i < len; ++i) {
|
|
1733
|
+
target[i + targetStart] = this[i + start];
|
|
1734
|
+
}
|
|
1735
|
+
} else {
|
|
1736
|
+
Uint8Array.prototype.set.call(
|
|
1737
|
+
target,
|
|
1738
|
+
this.subarray(start, start + len),
|
|
1739
|
+
targetStart
|
|
1740
|
+
);
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
return len
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
// Usage:
|
|
1747
|
+
// buffer.fill(number[, offset[, end]])
|
|
1748
|
+
// buffer.fill(buffer[, offset[, end]])
|
|
1749
|
+
// buffer.fill(string[, offset[, end]][, encoding])
|
|
1750
|
+
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
1751
|
+
// Handle string cases:
|
|
1752
|
+
if (typeof val === 'string') {
|
|
1753
|
+
if (typeof start === 'string') {
|
|
1754
|
+
encoding = start;
|
|
1755
|
+
start = 0;
|
|
1756
|
+
end = this.length;
|
|
1757
|
+
} else if (typeof end === 'string') {
|
|
1758
|
+
encoding = end;
|
|
1759
|
+
end = this.length;
|
|
1760
|
+
}
|
|
1761
|
+
if (val.length === 1) {
|
|
1762
|
+
var code = val.charCodeAt(0);
|
|
1763
|
+
if (code < 256) {
|
|
1764
|
+
val = code;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
1768
|
+
throw new TypeError('encoding must be a string')
|
|
1769
|
+
}
|
|
1770
|
+
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
1771
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
1772
|
+
}
|
|
1773
|
+
} else if (typeof val === 'number') {
|
|
1774
|
+
val = val & 255;
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
// Invalid ranges are not set to a default, so can range check early.
|
|
1778
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
1779
|
+
throw new RangeError('Out of range index')
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
if (end <= start) {
|
|
1783
|
+
return this
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
start = start >>> 0;
|
|
1787
|
+
end = end === undefined ? this.length : end >>> 0;
|
|
1788
|
+
|
|
1789
|
+
if (!val) val = 0;
|
|
1790
|
+
|
|
1791
|
+
var i;
|
|
1792
|
+
if (typeof val === 'number') {
|
|
1793
|
+
for (i = start; i < end; ++i) {
|
|
1794
|
+
this[i] = val;
|
|
1795
|
+
}
|
|
1796
|
+
} else {
|
|
1797
|
+
var bytes = internalIsBuffer(val)
|
|
1798
|
+
? val
|
|
1799
|
+
: utf8ToBytes(new Buffer(val, encoding).toString());
|
|
1800
|
+
var len = bytes.length;
|
|
1801
|
+
for (i = 0; i < end - start; ++i) {
|
|
1802
|
+
this[i + start] = bytes[i % len];
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
return this
|
|
1807
|
+
};
|
|
1808
|
+
|
|
1809
|
+
// HELPER FUNCTIONS
|
|
1810
|
+
// ================
|
|
1811
|
+
|
|
1812
|
+
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
|
|
1813
|
+
|
|
1814
|
+
function base64clean (str) {
|
|
1815
|
+
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
1816
|
+
str = stringtrim(str).replace(INVALID_BASE64_RE, '');
|
|
1817
|
+
// Node converts strings with length < 2 to ''
|
|
1818
|
+
if (str.length < 2) return ''
|
|
1819
|
+
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
1820
|
+
while (str.length % 4 !== 0) {
|
|
1821
|
+
str = str + '=';
|
|
1822
|
+
}
|
|
1823
|
+
return str
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
function stringtrim (str) {
|
|
1827
|
+
if (str.trim) return str.trim()
|
|
1828
|
+
return str.replace(/^\s+|\s+$/g, '')
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
function toHex (n) {
|
|
1832
|
+
if (n < 16) return '0' + n.toString(16)
|
|
1833
|
+
return n.toString(16)
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
function utf8ToBytes (string, units) {
|
|
1837
|
+
units = units || Infinity;
|
|
1838
|
+
var codePoint;
|
|
1839
|
+
var length = string.length;
|
|
1840
|
+
var leadSurrogate = null;
|
|
1841
|
+
var bytes = [];
|
|
1842
|
+
|
|
1843
|
+
for (var i = 0; i < length; ++i) {
|
|
1844
|
+
codePoint = string.charCodeAt(i);
|
|
1845
|
+
|
|
1846
|
+
// is surrogate component
|
|
1847
|
+
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
1848
|
+
// last char was a lead
|
|
1849
|
+
if (!leadSurrogate) {
|
|
1850
|
+
// no lead yet
|
|
1851
|
+
if (codePoint > 0xDBFF) {
|
|
1852
|
+
// unexpected trail
|
|
1853
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1854
|
+
continue
|
|
1855
|
+
} else if (i + 1 === length) {
|
|
1856
|
+
// unpaired lead
|
|
1857
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1858
|
+
continue
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
// valid lead
|
|
1862
|
+
leadSurrogate = codePoint;
|
|
1863
|
+
|
|
1864
|
+
continue
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// 2 leads in a row
|
|
1868
|
+
if (codePoint < 0xDC00) {
|
|
1869
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1870
|
+
leadSurrogate = codePoint;
|
|
1871
|
+
continue
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// valid surrogate pair
|
|
1875
|
+
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
|
1876
|
+
} else if (leadSurrogate) {
|
|
1877
|
+
// valid bmp char, but last char was a lead
|
|
1878
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
leadSurrogate = null;
|
|
1882
|
+
|
|
1883
|
+
// encode utf8
|
|
1884
|
+
if (codePoint < 0x80) {
|
|
1885
|
+
if ((units -= 1) < 0) break
|
|
1886
|
+
bytes.push(codePoint);
|
|
1887
|
+
} else if (codePoint < 0x800) {
|
|
1888
|
+
if ((units -= 2) < 0) break
|
|
1889
|
+
bytes.push(
|
|
1890
|
+
codePoint >> 0x6 | 0xC0,
|
|
1891
|
+
codePoint & 0x3F | 0x80
|
|
1892
|
+
);
|
|
1893
|
+
} else if (codePoint < 0x10000) {
|
|
1894
|
+
if ((units -= 3) < 0) break
|
|
1895
|
+
bytes.push(
|
|
1896
|
+
codePoint >> 0xC | 0xE0,
|
|
1897
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
1898
|
+
codePoint & 0x3F | 0x80
|
|
1899
|
+
);
|
|
1900
|
+
} else if (codePoint < 0x110000) {
|
|
1901
|
+
if ((units -= 4) < 0) break
|
|
1902
|
+
bytes.push(
|
|
1903
|
+
codePoint >> 0x12 | 0xF0,
|
|
1904
|
+
codePoint >> 0xC & 0x3F | 0x80,
|
|
1905
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
1906
|
+
codePoint & 0x3F | 0x80
|
|
1907
|
+
);
|
|
1908
|
+
} else {
|
|
1909
|
+
throw new Error('Invalid code point')
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
return bytes
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
function asciiToBytes (str) {
|
|
1917
|
+
var byteArray = [];
|
|
1918
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1919
|
+
// Node's code seems to be doing this and not & 0x7F..
|
|
1920
|
+
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
1921
|
+
}
|
|
1922
|
+
return byteArray
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
function utf16leToBytes (str, units) {
|
|
1926
|
+
var c, hi, lo;
|
|
1927
|
+
var byteArray = [];
|
|
1928
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1929
|
+
if ((units -= 2) < 0) break
|
|
1930
|
+
|
|
1931
|
+
c = str.charCodeAt(i);
|
|
1932
|
+
hi = c >> 8;
|
|
1933
|
+
lo = c % 256;
|
|
1934
|
+
byteArray.push(lo);
|
|
1935
|
+
byteArray.push(hi);
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
return byteArray
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
|
|
1942
|
+
function base64ToBytes (str) {
|
|
1943
|
+
return toByteArray(base64clean(str))
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
function blitBuffer (src, dst, offset, length) {
|
|
1947
|
+
for (var i = 0; i < length; ++i) {
|
|
1948
|
+
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
1949
|
+
dst[i + offset] = src[i];
|
|
1950
|
+
}
|
|
1951
|
+
return i
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
function isnan (val) {
|
|
1955
|
+
return val !== val // eslint-disable-line no-self-compare
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
|
|
1959
|
+
// the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
|
|
1960
|
+
// The _isBuffer check is for Safari 5-7 support, because it's missing
|
|
1961
|
+
// Object.prototype.constructor. Remove this eventually
|
|
1962
|
+
function isBuffer(obj) {
|
|
1963
|
+
return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
function isFastBuffer (obj) {
|
|
1967
|
+
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
// For Node v0.10 support. Remove this eventually.
|
|
1971
|
+
function isSlowBuffer (obj) {
|
|
1972
|
+
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
class CsvError extends Error {
|
|
1976
|
+
constructor(code, message, options, ...contexts) {
|
|
1977
|
+
if (Array.isArray(message)) message = message.join(" ").trim();
|
|
1978
|
+
super(message);
|
|
1979
|
+
if (Error.captureStackTrace !== undefined) {
|
|
1980
|
+
Error.captureStackTrace(this, CsvError);
|
|
1981
|
+
}
|
|
1982
|
+
this.code = code;
|
|
1983
|
+
for (const context of contexts) {
|
|
1984
|
+
for (const key in context) {
|
|
1985
|
+
const value = context[key];
|
|
1986
|
+
this[key] = isBuffer(value)
|
|
1987
|
+
? value.toString(options.encoding)
|
|
1988
|
+
: value == null
|
|
1989
|
+
? value
|
|
1990
|
+
: JSON.parse(JSON.stringify(value));
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
const is_object = function (obj) {
|
|
1997
|
+
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
1998
|
+
};
|
|
1999
|
+
|
|
2000
|
+
const normalize_columns_array = function (columns) {
|
|
2001
|
+
const normalizedColumns = [];
|
|
2002
|
+
for (let i = 0, l = columns.length; i < l; i++) {
|
|
2003
|
+
const column = columns[i];
|
|
2004
|
+
if (column === undefined || column === null || column === false) {
|
|
2005
|
+
normalizedColumns[i] = { disabled: true };
|
|
2006
|
+
} else if (typeof column === "string" || typeof column === "number") {
|
|
2007
|
+
normalizedColumns[i] = { name: `${column}` };
|
|
2008
|
+
} else if (is_object(column)) {
|
|
2009
|
+
if (typeof column.name !== "string") {
|
|
2010
|
+
throw new CsvError("CSV_OPTION_COLUMNS_MISSING_NAME", [
|
|
2011
|
+
"Option columns missing name:",
|
|
2012
|
+
`property "name" is required at position ${i}`,
|
|
2013
|
+
"when column is an object literal",
|
|
2014
|
+
]);
|
|
2015
|
+
}
|
|
2016
|
+
normalizedColumns[i] = column;
|
|
2017
|
+
} else {
|
|
2018
|
+
throw new CsvError("CSV_INVALID_COLUMN_DEFINITION", [
|
|
2019
|
+
"Invalid column definition:",
|
|
2020
|
+
"expect a string or a literal object,",
|
|
2021
|
+
`got ${JSON.stringify(column)} at position ${i}`,
|
|
2022
|
+
]);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
return normalizedColumns;
|
|
2026
|
+
};
|
|
2027
|
+
|
|
2028
|
+
class ResizeableBuffer {
|
|
2029
|
+
constructor(size = 100) {
|
|
2030
|
+
this.size = size;
|
|
2031
|
+
this.length = 0;
|
|
2032
|
+
this.buf = Buffer.allocUnsafe(size);
|
|
2033
|
+
}
|
|
2034
|
+
prepend(val) {
|
|
2035
|
+
if (isBuffer(val)) {
|
|
2036
|
+
const length = this.length + val.length;
|
|
2037
|
+
if (length >= this.size) {
|
|
2038
|
+
this.resize();
|
|
2039
|
+
if (length >= this.size) {
|
|
2040
|
+
throw Error("INVALID_BUFFER_STATE");
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
const buf = this.buf;
|
|
2044
|
+
this.buf = Buffer.allocUnsafe(this.size);
|
|
2045
|
+
val.copy(this.buf, 0);
|
|
2046
|
+
buf.copy(this.buf, val.length);
|
|
2047
|
+
this.length += val.length;
|
|
2048
|
+
} else {
|
|
2049
|
+
const length = this.length++;
|
|
2050
|
+
if (length === this.size) {
|
|
2051
|
+
this.resize();
|
|
2052
|
+
}
|
|
2053
|
+
const buf = this.clone();
|
|
2054
|
+
this.buf[0] = val;
|
|
2055
|
+
buf.copy(this.buf, 1, 0, length);
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
append(val) {
|
|
2059
|
+
const length = this.length++;
|
|
2060
|
+
if (length === this.size) {
|
|
2061
|
+
this.resize();
|
|
2062
|
+
}
|
|
2063
|
+
this.buf[length] = val;
|
|
2064
|
+
}
|
|
2065
|
+
clone() {
|
|
2066
|
+
return Buffer.from(this.buf.slice(0, this.length));
|
|
2067
|
+
}
|
|
2068
|
+
resize() {
|
|
2069
|
+
const length = this.length;
|
|
2070
|
+
this.size = this.size * 2;
|
|
2071
|
+
const buf = Buffer.allocUnsafe(this.size);
|
|
2072
|
+
this.buf.copy(buf, 0, 0, length);
|
|
2073
|
+
this.buf = buf;
|
|
2074
|
+
}
|
|
2075
|
+
toString(encoding) {
|
|
2076
|
+
if (encoding) {
|
|
2077
|
+
return this.buf.slice(0, this.length).toString(encoding);
|
|
2078
|
+
} else {
|
|
2079
|
+
return Uint8Array.prototype.slice.call(this.buf.slice(0, this.length));
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
toJSON() {
|
|
2083
|
+
return this.toString("utf8");
|
|
2084
|
+
}
|
|
2085
|
+
reset() {
|
|
2086
|
+
this.length = 0;
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
const init_state = function (options) {
|
|
2091
|
+
// ECMAScript WhiteSpace + LineTerminator codepoints, encoded under
|
|
2092
|
+
// `options.encoding`. Aligns trimming with `String.prototype.trim()`.
|
|
2093
|
+
// https://tc39.es/ecma262/#sec-white-space
|
|
2094
|
+
// https://tc39.es/ecma262/#sec-line-terminators
|
|
2095
|
+
//
|
|
2096
|
+
// Codepoints unrepresentable in the target encoding are dropped: Node's
|
|
2097
|
+
// Buffer substitutes them with `?` (0x3F), and including those would cause
|
|
2098
|
+
// literal `?` bytes in the input to be trimmed under `latin1`/`ascii`.
|
|
2099
|
+
const timchars = [
|
|
2100
|
+
// Basic Latin
|
|
2101
|
+
0x0020, // [Space](https://www.fileformat.info/info/unicode/char/0020/index.htm)
|
|
2102
|
+
0x0009, // [CHARACTER TABULATION (HT)](https://www.fileformat.info/info/unicode/char/0009/index.htm)
|
|
2103
|
+
0x000a, // [LINE FEED (LF)](https://www.fileformat.info/info/unicode/char/000a/index.htm)
|
|
2104
|
+
0x000d, // [CARRIAGE RETURN (CR)](https://www.fileformat.info/info/unicode/char/000d/index.htm)
|
|
2105
|
+
0x000c, // [FORM FEED (FF)](https://www.fileformat.info/info/unicode/char/000c/index.htm)
|
|
2106
|
+
0x000b, // [LINE TABULATION (VT)](https://www.fileformat.info/info/unicode/char/000b/index.htm)
|
|
2107
|
+
// Latin-1 Supplement
|
|
2108
|
+
0x00a0, // [NO-BREAK SPACE (NBSP)](https://www.fileformat.info/info/unicode/char/00a0/index.htm)
|
|
2109
|
+
// Ogham
|
|
2110
|
+
0x1680, // [OGHAM SPACE MARK](https://www.fileformat.info/info/unicode/char/1680/index.htm)
|
|
2111
|
+
// General Punctuation
|
|
2112
|
+
0x2000, // [EN QUAD](https://www.fileformat.info/info/unicode/char/2000/index.htm)
|
|
2113
|
+
0x2001, // [EM QUAD](https://www.fileformat.info/info/unicode/char/2001/index.htm)
|
|
2114
|
+
0x2002, // [EN SPACE](https://www.fileformat.info/info/unicode/char/2002/index.htm)
|
|
2115
|
+
0x2003, // [EM SPACE](https://www.fileformat.info/info/unicode/char/2003/index.htm)
|
|
2116
|
+
0x2004, // [THREE-PER-EM SPACE](https://www.fileformat.info/info/unicode/char/2004/index.htm)
|
|
2117
|
+
0x2005, // [FOUR-PER-EM SPACE](https://www.fileformat.info/info/unicode/char/2005/index.htm)
|
|
2118
|
+
0x2006, // [SIX-PER-EM SPACE](https://www.fileformat.info/info/unicode/char/2006/index.htm)
|
|
2119
|
+
0x2007, // [FIGURE SPACE](https://www.fileformat.info/info/unicode/char/2007/index.htm)
|
|
2120
|
+
0x2008, // [PUNCTUATION SPACE](https://www.fileformat.info/info/unicode/char/2008/index.htm)
|
|
2121
|
+
0x2009, // [THIN SPACE](https://www.fileformat.info/info/unicode/char/2009/index.htm)
|
|
2122
|
+
0x200a, // [HAIR SPACE](https://www.fileformat.info/info/unicode/char/200a/index.htm)
|
|
2123
|
+
0x2028, // [LINE SEPARATOR](https://www.fileformat.info/info/unicode/char/2028/index.htm)
|
|
2124
|
+
0x2029, // [PARAGRAPH SEPARATOR](https://www.fileformat.info/info/unicode/char/2029/index.htm)
|
|
2125
|
+
0x202f, // [NARROW NO-BREAK SPACE (NNBSP)](https://www.fileformat.info/info/unicode/char/202f/index.htm)
|
|
2126
|
+
0x205f, // [MEDIUM MATHEMATICAL SPACE (MMSP)](https://www.fileformat.info/info/unicode/char/205f/index.htm)
|
|
2127
|
+
0x3000, // [IDEOGRAPHIC SPACE](https://www.fileformat.info/info/unicode/char/3000/index.htm)
|
|
2128
|
+
0xfeff, // [ZERO WIDTH NO-BREAK SPACE (BOM)](https://www.fileformat.info/info/unicode/char/feff/index.htm)
|
|
2129
|
+
].reduce((acc, codepoint) => {
|
|
2130
|
+
const encoded = Buffer.from(
|
|
2131
|
+
String.fromCharCode(codepoint),
|
|
2132
|
+
options.encoding,
|
|
2133
|
+
);
|
|
2134
|
+
if (codepoint !== 0x3f && encoded.length === 1 && encoded[0] === 0x3f) {
|
|
2135
|
+
return acc;
|
|
2136
|
+
}
|
|
2137
|
+
acc.push(encoded);
|
|
2138
|
+
return acc;
|
|
2139
|
+
}, []);
|
|
2140
|
+
// First-byte lookup table for `__isCharTrimable`. Non-whitespace bytes
|
|
2141
|
+
// (the common case) bail out in O(1) without scanning every timchar.
|
|
2142
|
+
const timcharFirstBytes = new Uint8Array(256);
|
|
2143
|
+
for (const t of timchars) timcharFirstBytes[t[0]] = 1;
|
|
2144
|
+
return {
|
|
2145
|
+
bomSkipped: false,
|
|
2146
|
+
bufBytesStart: 0,
|
|
2147
|
+
castField: options.cast_function,
|
|
2148
|
+
commenting: false,
|
|
2149
|
+
delimiterBufPrevious: undefined,
|
|
2150
|
+
delimiterDiscovered: false,
|
|
2151
|
+
// Current error encountered by a record
|
|
2152
|
+
error: undefined,
|
|
2153
|
+
enabled: options.from_line === 1,
|
|
2154
|
+
escaping: false,
|
|
2155
|
+
escapeIsQuote:
|
|
2156
|
+
isBuffer(options.escape) &&
|
|
2157
|
+
isBuffer(options.quote) &&
|
|
2158
|
+
Buffer.compare(options.escape, options.quote) === 0,
|
|
2159
|
+
// columns can be `false`, `true`, `Array`
|
|
2160
|
+
expectedRecordLength: Array.isArray(options.columns)
|
|
2161
|
+
? options.columns.length
|
|
2162
|
+
: undefined,
|
|
2163
|
+
field: new ResizeableBuffer(20),
|
|
2164
|
+
firstLineToHeaders: options.cast_first_line_to_header,
|
|
2165
|
+
needMoreDataSize: Math.max(
|
|
2166
|
+
// Skip if the remaining buffer smaller than comment
|
|
2167
|
+
options.comment !== null ? options.comment.length : 0,
|
|
2168
|
+
// Skip if the remaining buffer can be delimiter
|
|
2169
|
+
...(options.delimiter
|
|
2170
|
+
? options.delimiter.map((delimiter) => delimiter.length)
|
|
2171
|
+
: []),
|
|
2172
|
+
// Auto discovery of delimiter is limited to 1 character
|
|
2173
|
+
options.delimiter_auto ? 1 : 0,
|
|
2174
|
+
// Skip if the remaining buffer can be escape sequence
|
|
2175
|
+
options.quote !== null ? options.quote.length : 0,
|
|
2176
|
+
// Skip if the remaining buffer can be a multi-byte trim character
|
|
2177
|
+
...timchars.map((t) => t.length),
|
|
2178
|
+
),
|
|
2179
|
+
previousBuf: undefined,
|
|
2180
|
+
quoting: false,
|
|
2181
|
+
stop: false,
|
|
2182
|
+
rawBuffer: new ResizeableBuffer(100),
|
|
2183
|
+
record: [],
|
|
2184
|
+
recordHasError: false,
|
|
2185
|
+
record_length: 0,
|
|
2186
|
+
recordDelimiterMaxLength:
|
|
2187
|
+
options.record_delimiter.length === 0
|
|
2188
|
+
? 0
|
|
2189
|
+
: Math.max(...options.record_delimiter.map((v) => v.length)),
|
|
2190
|
+
trimChars: [
|
|
2191
|
+
Buffer.from(" ", options.encoding)[0],
|
|
2192
|
+
Buffer.from("\t", options.encoding)[0],
|
|
2193
|
+
],
|
|
2194
|
+
wasQuoting: false,
|
|
2195
|
+
wasRowDelimiter: false,
|
|
2196
|
+
timchars: timchars,
|
|
2197
|
+
timcharFirstBytes: timcharFirstBytes,
|
|
2198
|
+
};
|
|
2199
|
+
};
|
|
2200
|
+
|
|
2201
|
+
const underscore = function (str) {
|
|
2202
|
+
return str.replace(/([A-Z])/g, function (_, match) {
|
|
2203
|
+
return "_" + match.toLowerCase();
|
|
2204
|
+
});
|
|
2205
|
+
};
|
|
2206
|
+
|
|
2207
|
+
const normalize_options = function (opts) {
|
|
2208
|
+
const options = {};
|
|
2209
|
+
// Merge with user options
|
|
2210
|
+
for (const opt in opts) {
|
|
2211
|
+
options[underscore(opt)] = opts[opt];
|
|
2212
|
+
}
|
|
2213
|
+
// Normalize option `encoding`
|
|
2214
|
+
// Note: defined first because other options depends on it
|
|
2215
|
+
// to convert chars/strings into buffers.
|
|
2216
|
+
if (options.encoding === undefined || options.encoding === true) {
|
|
2217
|
+
options.encoding = "utf8";
|
|
2218
|
+
} else if (options.encoding === null || options.encoding === false) {
|
|
2219
|
+
options.encoding = null;
|
|
2220
|
+
} else if (
|
|
2221
|
+
typeof options.encoding !== "string" &&
|
|
2222
|
+
options.encoding !== null
|
|
2223
|
+
) {
|
|
2224
|
+
throw new CsvError(
|
|
2225
|
+
"CSV_INVALID_OPTION_ENCODING",
|
|
2226
|
+
[
|
|
2227
|
+
"Invalid option encoding:",
|
|
2228
|
+
"encoding must be a string or null to return a buffer,",
|
|
2229
|
+
`got ${JSON.stringify(options.encoding)}`,
|
|
2230
|
+
],
|
|
2231
|
+
options,
|
|
2232
|
+
);
|
|
2233
|
+
}
|
|
2234
|
+
// Normalize option `bom`
|
|
2235
|
+
if (
|
|
2236
|
+
options.bom === undefined ||
|
|
2237
|
+
options.bom === null ||
|
|
2238
|
+
options.bom === false
|
|
2239
|
+
) {
|
|
2240
|
+
options.bom = false;
|
|
2241
|
+
} else if (options.bom !== true) {
|
|
2242
|
+
throw new CsvError(
|
|
2243
|
+
"CSV_INVALID_OPTION_BOM",
|
|
2244
|
+
[
|
|
2245
|
+
"Invalid option bom:",
|
|
2246
|
+
"bom must be true,",
|
|
2247
|
+
`got ${JSON.stringify(options.bom)}`,
|
|
2248
|
+
],
|
|
2249
|
+
options,
|
|
2250
|
+
);
|
|
2251
|
+
}
|
|
2252
|
+
// Normalize option `cast`
|
|
2253
|
+
options.cast_function = null;
|
|
2254
|
+
if (
|
|
2255
|
+
options.cast === undefined ||
|
|
2256
|
+
options.cast === null ||
|
|
2257
|
+
options.cast === false ||
|
|
2258
|
+
options.cast === ""
|
|
2259
|
+
) {
|
|
2260
|
+
options.cast = undefined;
|
|
2261
|
+
} else if (typeof options.cast === "function") {
|
|
2262
|
+
options.cast_function = options.cast;
|
|
2263
|
+
options.cast = true;
|
|
2264
|
+
} else if (options.cast !== true) {
|
|
2265
|
+
throw new CsvError(
|
|
2266
|
+
"CSV_INVALID_OPTION_CAST",
|
|
2267
|
+
[
|
|
2268
|
+
"Invalid option cast:",
|
|
2269
|
+
"cast must be true or a function,",
|
|
2270
|
+
`got ${JSON.stringify(options.cast)}`,
|
|
2271
|
+
],
|
|
2272
|
+
options,
|
|
2273
|
+
);
|
|
2274
|
+
}
|
|
2275
|
+
// Normalize option `cast_date`
|
|
2276
|
+
if (
|
|
2277
|
+
options.cast_date === undefined ||
|
|
2278
|
+
options.cast_date === null ||
|
|
2279
|
+
options.cast_date === false ||
|
|
2280
|
+
options.cast_date === ""
|
|
2281
|
+
) {
|
|
2282
|
+
options.cast_date = false;
|
|
2283
|
+
} else if (options.cast_date === true) {
|
|
2284
|
+
options.cast_date = function (value) {
|
|
2285
|
+
const date = Date.parse(value);
|
|
2286
|
+
return !isNaN(date) ? new Date(date) : value;
|
|
2287
|
+
};
|
|
2288
|
+
} else if (typeof options.cast_date !== "function") {
|
|
2289
|
+
throw new CsvError(
|
|
2290
|
+
"CSV_INVALID_OPTION_CAST_DATE",
|
|
2291
|
+
[
|
|
2292
|
+
"Invalid option cast_date:",
|
|
2293
|
+
"cast_date must be true or a function,",
|
|
2294
|
+
`got ${JSON.stringify(options.cast_date)}`,
|
|
2295
|
+
],
|
|
2296
|
+
options,
|
|
2297
|
+
);
|
|
2298
|
+
}
|
|
2299
|
+
// Normalize option `columns`
|
|
2300
|
+
options.cast_first_line_to_header = undefined;
|
|
2301
|
+
if (options.columns === true) {
|
|
2302
|
+
// Fields in the first line are converted as-is to columns
|
|
2303
|
+
options.cast_first_line_to_header = undefined;
|
|
2304
|
+
} else if (typeof options.columns === "function") {
|
|
2305
|
+
options.cast_first_line_to_header = options.columns;
|
|
2306
|
+
options.columns = true;
|
|
2307
|
+
} else if (Array.isArray(options.columns)) {
|
|
2308
|
+
options.columns = normalize_columns_array(options.columns);
|
|
2309
|
+
} else if (
|
|
2310
|
+
options.columns === undefined ||
|
|
2311
|
+
options.columns === null ||
|
|
2312
|
+
options.columns === false
|
|
2313
|
+
) {
|
|
2314
|
+
options.columns = false;
|
|
2315
|
+
} else {
|
|
2316
|
+
throw new CsvError(
|
|
2317
|
+
"CSV_INVALID_OPTION_COLUMNS",
|
|
2318
|
+
[
|
|
2319
|
+
"Invalid option columns:",
|
|
2320
|
+
"expect an array, a function or true,",
|
|
2321
|
+
`got ${JSON.stringify(options.columns)}`,
|
|
2322
|
+
],
|
|
2323
|
+
options,
|
|
2324
|
+
);
|
|
2325
|
+
}
|
|
2326
|
+
// Normalize option `group_columns_by_name`
|
|
2327
|
+
if (
|
|
2328
|
+
options.group_columns_by_name === undefined ||
|
|
2329
|
+
options.group_columns_by_name === null ||
|
|
2330
|
+
options.group_columns_by_name === false
|
|
2331
|
+
) {
|
|
2332
|
+
options.group_columns_by_name = false;
|
|
2333
|
+
} else if (options.group_columns_by_name !== true) {
|
|
2334
|
+
throw new CsvError(
|
|
2335
|
+
"CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",
|
|
2336
|
+
[
|
|
2337
|
+
"Invalid option group_columns_by_name:",
|
|
2338
|
+
"expect an boolean,",
|
|
2339
|
+
`got ${JSON.stringify(options.group_columns_by_name)}`,
|
|
2340
|
+
],
|
|
2341
|
+
options,
|
|
2342
|
+
);
|
|
2343
|
+
} else if (options.columns === false) {
|
|
2344
|
+
throw new CsvError(
|
|
2345
|
+
"CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",
|
|
2346
|
+
[
|
|
2347
|
+
"Invalid option group_columns_by_name:",
|
|
2348
|
+
"the `columns` mode must be activated.",
|
|
2349
|
+
],
|
|
2350
|
+
options,
|
|
2351
|
+
);
|
|
2352
|
+
}
|
|
2353
|
+
// Normalize option `comment`
|
|
2354
|
+
if (
|
|
2355
|
+
options.comment === undefined ||
|
|
2356
|
+
options.comment === null ||
|
|
2357
|
+
options.comment === false ||
|
|
2358
|
+
options.comment === ""
|
|
2359
|
+
) {
|
|
2360
|
+
options.comment = null;
|
|
2361
|
+
} else {
|
|
2362
|
+
if (typeof options.comment === "string") {
|
|
2363
|
+
options.comment = Buffer.from(options.comment, options.encoding);
|
|
2364
|
+
}
|
|
2365
|
+
if (!isBuffer(options.comment)) {
|
|
2366
|
+
throw new CsvError(
|
|
2367
|
+
"CSV_INVALID_OPTION_COMMENT",
|
|
2368
|
+
[
|
|
2369
|
+
"Invalid option comment:",
|
|
2370
|
+
"comment must be a buffer or a string,",
|
|
2371
|
+
`got ${JSON.stringify(options.comment)}`,
|
|
2372
|
+
],
|
|
2373
|
+
options,
|
|
2374
|
+
);
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
// Normalize option `comment_no_infix`
|
|
2378
|
+
if (
|
|
2379
|
+
options.comment_no_infix === undefined ||
|
|
2380
|
+
options.comment_no_infix === null ||
|
|
2381
|
+
options.comment_no_infix === false
|
|
2382
|
+
) {
|
|
2383
|
+
options.comment_no_infix = false;
|
|
2384
|
+
} else if (options.comment_no_infix !== true) {
|
|
2385
|
+
throw new CsvError(
|
|
2386
|
+
"CSV_INVALID_OPTION_COMMENT",
|
|
2387
|
+
[
|
|
2388
|
+
"Invalid option comment_no_infix:",
|
|
2389
|
+
"value must be a boolean,",
|
|
2390
|
+
`got ${JSON.stringify(options.comment_no_infix)}`,
|
|
2391
|
+
],
|
|
2392
|
+
options,
|
|
2393
|
+
);
|
|
2394
|
+
}
|
|
2395
|
+
// Normalize option `delimiter_auto`
|
|
2396
|
+
if (
|
|
2397
|
+
options.delimiter_auto === undefined ||
|
|
2398
|
+
options.delimiter_auto === null ||
|
|
2399
|
+
options.delimiter_auto === false
|
|
2400
|
+
) {
|
|
2401
|
+
options.delimiter_auto = false;
|
|
2402
|
+
} else if (options.delimiter_auto === true) {
|
|
2403
|
+
options.delimiter_auto = {};
|
|
2404
|
+
} else if (!is_object(options.delimiter_auto)) {
|
|
2405
|
+
throw new CsvError(
|
|
2406
|
+
"CSV_INVALID_OPTION_DELIMITER_AUTO",
|
|
2407
|
+
[
|
|
2408
|
+
"Invalid option delimiter_auto:",
|
|
2409
|
+
"delimiter_auto must be a boolean or a configuration object,",
|
|
2410
|
+
`got ${JSON.stringify(options.delimiter_auto)}`,
|
|
2411
|
+
],
|
|
2412
|
+
options,
|
|
2413
|
+
);
|
|
2414
|
+
}
|
|
2415
|
+
if (options.delimiter_auto) {
|
|
2416
|
+
if (options.delimiter_auto.preferred === undefined)
|
|
2417
|
+
options.delimiter_auto.preferred = {
|
|
2418
|
+
[",".charCodeAt(0)]: 1.8,
|
|
2419
|
+
["\t".charCodeAt(0)]: 1.8,
|
|
2420
|
+
[";".charCodeAt(0)]: 1.6,
|
|
2421
|
+
[" ".charCodeAt(0)]: 1.6,
|
|
2422
|
+
[":".charCodeAt(0)]: 1.5,
|
|
2423
|
+
[".".charCodeAt(0)]: 1.4,
|
|
2424
|
+
["/".charCodeAt(0)]: 1.4,
|
|
2425
|
+
};
|
|
2426
|
+
else if (!is_object(options.delimiter_auto.preferred)) {
|
|
2427
|
+
throw new CsvError(
|
|
2428
|
+
"CSV_INVALID_OPTION_DELIMITER_AUTO",
|
|
2429
|
+
[
|
|
2430
|
+
"Invalid option delimiter_auto:",
|
|
2431
|
+
"preferred must be an object,",
|
|
2432
|
+
`got ${JSON.stringify(options.delimiter_auto.preferred)}`,
|
|
2433
|
+
],
|
|
2434
|
+
options,
|
|
2435
|
+
);
|
|
2436
|
+
}
|
|
2437
|
+
if (options.delimiter_auto.score === undefined)
|
|
2438
|
+
options.delimiter_auto.score = (info, options) => {
|
|
2439
|
+
return (
|
|
2440
|
+
(info.total - info.std) * (options.preferred[info.char_code] || 1)
|
|
2441
|
+
);
|
|
2442
|
+
};
|
|
2443
|
+
else if (typeof options.delimiter_auto.score !== "function") {
|
|
2444
|
+
throw new CsvError(
|
|
2445
|
+
"CSV_INVALID_OPTION_DELIMITER_AUTO",
|
|
2446
|
+
[
|
|
2447
|
+
"Invalid option delimiter_auto:",
|
|
2448
|
+
"score must be a function,",
|
|
2449
|
+
`got ${JSON.stringify(options.delimiter_auto.score)}`,
|
|
2450
|
+
],
|
|
2451
|
+
options,
|
|
2452
|
+
);
|
|
2453
|
+
}
|
|
2454
|
+
if (options.delimiter_auto.size === undefined)
|
|
2455
|
+
options.delimiter_auto.size = 2048;
|
|
2456
|
+
else if (typeof options.delimiter_auto.size !== "number") {
|
|
2457
|
+
throw new CsvError(
|
|
2458
|
+
"CSV_INVALID_OPTION_DELIMITER_AUTO",
|
|
2459
|
+
[
|
|
2460
|
+
"Invalid option delimiter_auto:",
|
|
2461
|
+
"size must be a number,",
|
|
2462
|
+
`got ${JSON.stringify(options.delimiter_auto.size)}`,
|
|
2463
|
+
],
|
|
2464
|
+
options,
|
|
2465
|
+
);
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
// Normalize option `delimiter`
|
|
2469
|
+
const delimiter_json = JSON.stringify(options.delimiter);
|
|
2470
|
+
if (options.delimiter_auto !== false) {
|
|
2471
|
+
options.delimiter = [];
|
|
2472
|
+
}
|
|
2473
|
+
if (!Array.isArray(options.delimiter)) {
|
|
2474
|
+
if (
|
|
2475
|
+
options.delimiter === undefined ||
|
|
2476
|
+
options.delimiter === null ||
|
|
2477
|
+
options.delimiter === false
|
|
2478
|
+
) {
|
|
2479
|
+
options.delimiter = Buffer.from(",", options.encoding);
|
|
2480
|
+
}
|
|
2481
|
+
options.delimiter = [options.delimiter];
|
|
2482
|
+
}
|
|
2483
|
+
options.delimiter = options.delimiter.map(function (delimiter) {
|
|
2484
|
+
if (typeof delimiter === "string") {
|
|
2485
|
+
delimiter = Buffer.from(delimiter, options.encoding);
|
|
2486
|
+
}
|
|
2487
|
+
if (!isBuffer(delimiter) || delimiter.length === 0) {
|
|
2488
|
+
throw new CsvError(
|
|
2489
|
+
"CSV_INVALID_OPTION_DELIMITER",
|
|
2490
|
+
[
|
|
2491
|
+
"Invalid option delimiter:",
|
|
2492
|
+
"delimiter must be a non empty string or buffer or array of string|buffer,",
|
|
2493
|
+
`got ${delimiter_json}`,
|
|
2494
|
+
],
|
|
2495
|
+
options,
|
|
2496
|
+
);
|
|
2497
|
+
}
|
|
2498
|
+
return delimiter;
|
|
2499
|
+
});
|
|
2500
|
+
// Normalize option `escape`
|
|
2501
|
+
if (options.escape === undefined || options.escape === true) {
|
|
2502
|
+
options.escape = Buffer.from('"', options.encoding);
|
|
2503
|
+
} else if (typeof options.escape === "string") {
|
|
2504
|
+
options.escape = Buffer.from(options.escape, options.encoding);
|
|
2505
|
+
} else if (options.escape === null || options.escape === false) {
|
|
2506
|
+
options.escape = null;
|
|
2507
|
+
}
|
|
2508
|
+
if (options.escape !== null) {
|
|
2509
|
+
if (!isBuffer(options.escape)) {
|
|
2510
|
+
throw new Error(
|
|
2511
|
+
`Invalid Option: escape must be a buffer, a string or a boolean, got ${JSON.stringify(options.escape)}`,
|
|
2512
|
+
);
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
// Normalize option `from`
|
|
2516
|
+
if (options.from === undefined || options.from === null) {
|
|
2517
|
+
options.from = 1;
|
|
2518
|
+
} else {
|
|
2519
|
+
if (typeof options.from === "string" && /\d+/.test(options.from)) {
|
|
2520
|
+
options.from = parseInt(options.from);
|
|
2521
|
+
}
|
|
2522
|
+
if (Number.isInteger(options.from)) {
|
|
2523
|
+
if (options.from < 0) {
|
|
2524
|
+
throw new Error(
|
|
2525
|
+
`Invalid Option: from must be a positive integer, got ${JSON.stringify(opts.from)}`,
|
|
2526
|
+
);
|
|
2527
|
+
}
|
|
2528
|
+
} else {
|
|
2529
|
+
throw new Error(
|
|
2530
|
+
`Invalid Option: from must be an integer, got ${JSON.stringify(options.from)}`,
|
|
2531
|
+
);
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
// Normalize option `from_line`
|
|
2535
|
+
if (options.from_line === undefined || options.from_line === null) {
|
|
2536
|
+
options.from_line = 1;
|
|
2537
|
+
} else {
|
|
2538
|
+
if (
|
|
2539
|
+
typeof options.from_line === "string" &&
|
|
2540
|
+
/\d+/.test(options.from_line)
|
|
2541
|
+
) {
|
|
2542
|
+
options.from_line = parseInt(options.from_line);
|
|
2543
|
+
}
|
|
2544
|
+
if (Number.isInteger(options.from_line)) {
|
|
2545
|
+
if (options.from_line <= 0) {
|
|
2546
|
+
throw new Error(
|
|
2547
|
+
`Invalid Option: from_line must be a positive integer greater than 0, got ${JSON.stringify(opts.from_line)}`,
|
|
2548
|
+
);
|
|
2549
|
+
}
|
|
2550
|
+
} else {
|
|
2551
|
+
throw new Error(
|
|
2552
|
+
`Invalid Option: from_line must be an integer, got ${JSON.stringify(opts.from_line)}`,
|
|
2553
|
+
);
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
// Normalize options `ignore_last_delimiters`
|
|
2557
|
+
if (
|
|
2558
|
+
options.ignore_last_delimiters === undefined ||
|
|
2559
|
+
options.ignore_last_delimiters === null
|
|
2560
|
+
) {
|
|
2561
|
+
options.ignore_last_delimiters = false;
|
|
2562
|
+
} else if (typeof options.ignore_last_delimiters === "number") {
|
|
2563
|
+
options.ignore_last_delimiters = Math.floor(options.ignore_last_delimiters);
|
|
2564
|
+
if (options.ignore_last_delimiters === 0) {
|
|
2565
|
+
options.ignore_last_delimiters = false;
|
|
2566
|
+
}
|
|
2567
|
+
} else if (typeof options.ignore_last_delimiters !== "boolean") {
|
|
2568
|
+
throw new CsvError(
|
|
2569
|
+
"CSV_INVALID_OPTION_IGNORE_LAST_DELIMITERS",
|
|
2570
|
+
[
|
|
2571
|
+
"Invalid option `ignore_last_delimiters`:",
|
|
2572
|
+
"the value must be a boolean value or an integer,",
|
|
2573
|
+
`got ${JSON.stringify(options.ignore_last_delimiters)}`,
|
|
2574
|
+
],
|
|
2575
|
+
options,
|
|
2576
|
+
);
|
|
2577
|
+
}
|
|
2578
|
+
if (options.ignore_last_delimiters === true && options.columns === false) {
|
|
2579
|
+
throw new CsvError(
|
|
2580
|
+
"CSV_IGNORE_LAST_DELIMITERS_REQUIRES_COLUMNS",
|
|
2581
|
+
[
|
|
2582
|
+
"The option `ignore_last_delimiters`",
|
|
2583
|
+
"requires the activation of the `columns` option",
|
|
2584
|
+
],
|
|
2585
|
+
options,
|
|
2586
|
+
);
|
|
2587
|
+
}
|
|
2588
|
+
// Normalize option `info`
|
|
2589
|
+
if (
|
|
2590
|
+
options.info === undefined ||
|
|
2591
|
+
options.info === null ||
|
|
2592
|
+
options.info === false
|
|
2593
|
+
) {
|
|
2594
|
+
options.info = false;
|
|
2595
|
+
} else if (options.info !== true) {
|
|
2596
|
+
throw new Error(
|
|
2597
|
+
`Invalid Option: info must be true, got ${JSON.stringify(options.info)}`,
|
|
2598
|
+
);
|
|
2599
|
+
}
|
|
2600
|
+
// Normalize option `max_record_size`
|
|
2601
|
+
if (
|
|
2602
|
+
options.max_record_size === undefined ||
|
|
2603
|
+
options.max_record_size === null ||
|
|
2604
|
+
options.max_record_size === false
|
|
2605
|
+
) {
|
|
2606
|
+
options.max_record_size = 0;
|
|
2607
|
+
} else if (
|
|
2608
|
+
Number.isInteger(options.max_record_size) &&
|
|
2609
|
+
options.max_record_size >= 0
|
|
2610
|
+
) ; else if (
|
|
2611
|
+
typeof options.max_record_size === "string" &&
|
|
2612
|
+
/\d+/.test(options.max_record_size)
|
|
2613
|
+
) {
|
|
2614
|
+
options.max_record_size = parseInt(options.max_record_size);
|
|
2615
|
+
} else {
|
|
2616
|
+
throw new Error(
|
|
2617
|
+
`Invalid Option: max_record_size must be a positive integer, got ${JSON.stringify(options.max_record_size)}`,
|
|
2618
|
+
);
|
|
2619
|
+
}
|
|
2620
|
+
// Normalize option `objname`
|
|
2621
|
+
if (
|
|
2622
|
+
options.objname === undefined ||
|
|
2623
|
+
options.objname === null ||
|
|
2624
|
+
options.objname === false
|
|
2625
|
+
) {
|
|
2626
|
+
options.objname = undefined;
|
|
2627
|
+
} else if (isBuffer(options.objname)) {
|
|
2628
|
+
if (options.objname.length === 0) {
|
|
2629
|
+
throw new Error(`Invalid Option: objname must be a non empty buffer`);
|
|
2630
|
+
}
|
|
2631
|
+
if (options.encoding === null) ; else {
|
|
2632
|
+
options.objname = options.objname.toString(options.encoding);
|
|
2633
|
+
}
|
|
2634
|
+
} else if (typeof options.objname === "string") {
|
|
2635
|
+
if (options.objname.length === 0) {
|
|
2636
|
+
throw new Error(`Invalid Option: objname must be a non empty string`);
|
|
2637
|
+
}
|
|
2638
|
+
// Great, nothing to do
|
|
2639
|
+
} else if (typeof options.objname === "number") ; else {
|
|
2640
|
+
throw new Error(
|
|
2641
|
+
`Invalid Option: objname must be a string or a buffer, got ${options.objname}`,
|
|
2642
|
+
);
|
|
2643
|
+
}
|
|
2644
|
+
if (options.objname !== undefined) {
|
|
2645
|
+
if (typeof options.objname === "number") {
|
|
2646
|
+
if (options.columns !== false) {
|
|
2647
|
+
throw Error(
|
|
2648
|
+
"Invalid Option: objname index cannot be combined with columns or be defined as a field",
|
|
2649
|
+
);
|
|
2650
|
+
}
|
|
2651
|
+
} else {
|
|
2652
|
+
// A string or a buffer
|
|
2653
|
+
if (options.columns === false) {
|
|
2654
|
+
throw Error(
|
|
2655
|
+
"Invalid Option: objname field must be combined with columns or be defined as an index",
|
|
2656
|
+
);
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
// Normalize option `on_record`
|
|
2661
|
+
if (options.on_record === undefined || options.on_record === null) {
|
|
2662
|
+
options.on_record = undefined;
|
|
2663
|
+
} else if (typeof options.on_record !== "function") {
|
|
2664
|
+
throw new CsvError(
|
|
2665
|
+
"CSV_INVALID_OPTION_ON_RECORD",
|
|
2666
|
+
[
|
|
2667
|
+
"Invalid option `on_record`:",
|
|
2668
|
+
"expect a function,",
|
|
2669
|
+
`got ${JSON.stringify(options.on_record)}`,
|
|
2670
|
+
],
|
|
2671
|
+
options,
|
|
2672
|
+
);
|
|
2673
|
+
}
|
|
2674
|
+
// Normalize option `on_skip`
|
|
2675
|
+
// options.on_skip ??= (err, chunk) => {
|
|
2676
|
+
// this.emit('skip', err, chunk);
|
|
2677
|
+
// };
|
|
2678
|
+
if (
|
|
2679
|
+
options.on_skip !== undefined &&
|
|
2680
|
+
options.on_skip !== null &&
|
|
2681
|
+
typeof options.on_skip !== "function"
|
|
2682
|
+
) {
|
|
2683
|
+
throw new Error(
|
|
2684
|
+
`Invalid Option: on_skip must be a function, got ${JSON.stringify(options.on_skip)}`,
|
|
2685
|
+
);
|
|
2686
|
+
}
|
|
2687
|
+
// Normalize option `quote`
|
|
2688
|
+
if (
|
|
2689
|
+
options.quote === null ||
|
|
2690
|
+
options.quote === false ||
|
|
2691
|
+
options.quote === ""
|
|
2692
|
+
) {
|
|
2693
|
+
options.quote = null;
|
|
2694
|
+
} else {
|
|
2695
|
+
if (options.quote === undefined || options.quote === true) {
|
|
2696
|
+
options.quote = Buffer.from('"', options.encoding);
|
|
2697
|
+
} else if (typeof options.quote === "string") {
|
|
2698
|
+
options.quote = Buffer.from(options.quote, options.encoding);
|
|
2699
|
+
}
|
|
2700
|
+
if (!isBuffer(options.quote)) {
|
|
2701
|
+
throw new Error(
|
|
2702
|
+
`Invalid Option: quote must be a buffer or a string, got ${JSON.stringify(options.quote)}`,
|
|
2703
|
+
);
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
// Normalize option `raw`
|
|
2707
|
+
if (
|
|
2708
|
+
options.raw === undefined ||
|
|
2709
|
+
options.raw === null ||
|
|
2710
|
+
options.raw === false
|
|
2711
|
+
) {
|
|
2712
|
+
options.raw = false;
|
|
2713
|
+
} else if (options.raw !== true) {
|
|
2714
|
+
throw new Error(
|
|
2715
|
+
`Invalid Option: raw must be true, got ${JSON.stringify(options.raw)}`,
|
|
2716
|
+
);
|
|
2717
|
+
}
|
|
2718
|
+
// Normalize option `record_delimiter`
|
|
2719
|
+
if (options.record_delimiter === undefined) {
|
|
2720
|
+
options.record_delimiter = [];
|
|
2721
|
+
} else if (
|
|
2722
|
+
typeof options.record_delimiter === "string" ||
|
|
2723
|
+
isBuffer(options.record_delimiter)
|
|
2724
|
+
) {
|
|
2725
|
+
if (options.record_delimiter.length === 0) {
|
|
2726
|
+
throw new CsvError(
|
|
2727
|
+
"CSV_INVALID_OPTION_RECORD_DELIMITER",
|
|
2728
|
+
[
|
|
2729
|
+
"Invalid option `record_delimiter`:",
|
|
2730
|
+
"value must be a non empty string or buffer,",
|
|
2731
|
+
`got ${JSON.stringify(options.record_delimiter)}`,
|
|
2732
|
+
],
|
|
2733
|
+
options,
|
|
2734
|
+
);
|
|
2735
|
+
}
|
|
2736
|
+
options.record_delimiter = [options.record_delimiter];
|
|
2737
|
+
} else if (!Array.isArray(options.record_delimiter)) {
|
|
2738
|
+
throw new CsvError(
|
|
2739
|
+
"CSV_INVALID_OPTION_RECORD_DELIMITER",
|
|
2740
|
+
[
|
|
2741
|
+
"Invalid option `record_delimiter`:",
|
|
2742
|
+
"value must be a string, a buffer or array of string|buffer,",
|
|
2743
|
+
`got ${JSON.stringify(options.record_delimiter)}`,
|
|
2744
|
+
],
|
|
2745
|
+
options,
|
|
2746
|
+
);
|
|
2747
|
+
}
|
|
2748
|
+
options.record_delimiter = options.record_delimiter.map(function (rd, i) {
|
|
2749
|
+
if (typeof rd !== "string" && !isBuffer(rd)) {
|
|
2750
|
+
throw new CsvError(
|
|
2751
|
+
"CSV_INVALID_OPTION_RECORD_DELIMITER",
|
|
2752
|
+
[
|
|
2753
|
+
"Invalid option `record_delimiter`:",
|
|
2754
|
+
"value must be a string, a buffer or array of string|buffer",
|
|
2755
|
+
`at index ${i},`,
|
|
2756
|
+
`got ${JSON.stringify(rd)}`,
|
|
2757
|
+
],
|
|
2758
|
+
options,
|
|
2759
|
+
);
|
|
2760
|
+
} else if (rd.length === 0) {
|
|
2761
|
+
throw new CsvError(
|
|
2762
|
+
"CSV_INVALID_OPTION_RECORD_DELIMITER",
|
|
2763
|
+
[
|
|
2764
|
+
"Invalid option `record_delimiter`:",
|
|
2765
|
+
"value must be a non empty string or buffer",
|
|
2766
|
+
`at index ${i},`,
|
|
2767
|
+
`got ${JSON.stringify(rd)}`,
|
|
2768
|
+
],
|
|
2769
|
+
options,
|
|
2770
|
+
);
|
|
2771
|
+
}
|
|
2772
|
+
if (typeof rd === "string") {
|
|
2773
|
+
rd = Buffer.from(rd, options.encoding);
|
|
2774
|
+
}
|
|
2775
|
+
return rd;
|
|
2776
|
+
});
|
|
2777
|
+
// Normalize option `relax_column_count`
|
|
2778
|
+
if (typeof options.relax_column_count === "boolean") ; else if (
|
|
2779
|
+
options.relax_column_count === undefined ||
|
|
2780
|
+
options.relax_column_count === null
|
|
2781
|
+
) {
|
|
2782
|
+
options.relax_column_count = false;
|
|
2783
|
+
} else {
|
|
2784
|
+
throw new Error(
|
|
2785
|
+
`Invalid Option: relax_column_count must be a boolean, got ${JSON.stringify(options.relax_column_count)}`,
|
|
2786
|
+
);
|
|
2787
|
+
}
|
|
2788
|
+
if (typeof options.relax_column_count_less === "boolean") ; else if (
|
|
2789
|
+
options.relax_column_count_less === undefined ||
|
|
2790
|
+
options.relax_column_count_less === null
|
|
2791
|
+
) {
|
|
2792
|
+
options.relax_column_count_less = false;
|
|
2793
|
+
} else {
|
|
2794
|
+
throw new Error(
|
|
2795
|
+
`Invalid Option: relax_column_count_less must be a boolean, got ${JSON.stringify(options.relax_column_count_less)}`,
|
|
2796
|
+
);
|
|
2797
|
+
}
|
|
2798
|
+
if (typeof options.relax_column_count_more === "boolean") ; else if (
|
|
2799
|
+
options.relax_column_count_more === undefined ||
|
|
2800
|
+
options.relax_column_count_more === null
|
|
2801
|
+
) {
|
|
2802
|
+
options.relax_column_count_more = false;
|
|
2803
|
+
} else {
|
|
2804
|
+
throw new Error(
|
|
2805
|
+
`Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`,
|
|
2806
|
+
);
|
|
2807
|
+
}
|
|
2808
|
+
// Normalize option `relax_quotes`
|
|
2809
|
+
if (typeof options.relax_quotes === "boolean") ; else if (
|
|
2810
|
+
options.relax_quotes === undefined ||
|
|
2811
|
+
options.relax_quotes === null
|
|
2812
|
+
) {
|
|
2813
|
+
options.relax_quotes = false;
|
|
2814
|
+
} else {
|
|
2815
|
+
throw new Error(
|
|
2816
|
+
`Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`,
|
|
2817
|
+
);
|
|
2818
|
+
}
|
|
2819
|
+
// Normalize option `skip_empty_lines`
|
|
2820
|
+
if (typeof options.skip_empty_lines === "boolean") ; else if (
|
|
2821
|
+
options.skip_empty_lines === undefined ||
|
|
2822
|
+
options.skip_empty_lines === null
|
|
2823
|
+
) {
|
|
2824
|
+
options.skip_empty_lines = false;
|
|
2825
|
+
} else {
|
|
2826
|
+
throw new Error(
|
|
2827
|
+
`Invalid Option: skip_empty_lines must be a boolean, got ${JSON.stringify(options.skip_empty_lines)}`,
|
|
2828
|
+
);
|
|
2829
|
+
}
|
|
2830
|
+
// Normalize option `skip_records_with_empty_values`
|
|
2831
|
+
if (typeof options.skip_records_with_empty_values === "boolean") ; else if (
|
|
2832
|
+
options.skip_records_with_empty_values === undefined ||
|
|
2833
|
+
options.skip_records_with_empty_values === null
|
|
2834
|
+
) {
|
|
2835
|
+
options.skip_records_with_empty_values = false;
|
|
2836
|
+
} else {
|
|
2837
|
+
throw new Error(
|
|
2838
|
+
`Invalid Option: skip_records_with_empty_values must be a boolean, got ${JSON.stringify(options.skip_records_with_empty_values)}`,
|
|
2839
|
+
);
|
|
2840
|
+
}
|
|
2841
|
+
// Normalize option `skip_records_with_error`
|
|
2842
|
+
if (typeof options.skip_records_with_error === "boolean") ; else if (
|
|
2843
|
+
options.skip_records_with_error === undefined ||
|
|
2844
|
+
options.skip_records_with_error === null
|
|
2845
|
+
) {
|
|
2846
|
+
options.skip_records_with_error = false;
|
|
2847
|
+
} else {
|
|
2848
|
+
throw new Error(
|
|
2849
|
+
`Invalid Option: skip_records_with_error must be a boolean, got ${JSON.stringify(options.skip_records_with_error)}`,
|
|
2850
|
+
);
|
|
2851
|
+
}
|
|
2852
|
+
// Normalize option `rtrim`
|
|
2853
|
+
if (
|
|
2854
|
+
options.rtrim === undefined ||
|
|
2855
|
+
options.rtrim === null ||
|
|
2856
|
+
options.rtrim === false
|
|
2857
|
+
) {
|
|
2858
|
+
options.rtrim = false;
|
|
2859
|
+
} else if (options.rtrim !== true) {
|
|
2860
|
+
throw new Error(
|
|
2861
|
+
`Invalid Option: rtrim must be a boolean, got ${JSON.stringify(options.rtrim)}`,
|
|
2862
|
+
);
|
|
2863
|
+
}
|
|
2864
|
+
// Normalize option `ltrim`
|
|
2865
|
+
if (
|
|
2866
|
+
options.ltrim === undefined ||
|
|
2867
|
+
options.ltrim === null ||
|
|
2868
|
+
options.ltrim === false
|
|
2869
|
+
) {
|
|
2870
|
+
options.ltrim = false;
|
|
2871
|
+
} else if (options.ltrim !== true) {
|
|
2872
|
+
throw new Error(
|
|
2873
|
+
`Invalid Option: ltrim must be a boolean, got ${JSON.stringify(options.ltrim)}`,
|
|
2874
|
+
);
|
|
2875
|
+
}
|
|
2876
|
+
// Normalize option `trim`
|
|
2877
|
+
if (
|
|
2878
|
+
options.trim === undefined ||
|
|
2879
|
+
options.trim === null ||
|
|
2880
|
+
options.trim === false
|
|
2881
|
+
) {
|
|
2882
|
+
options.trim = false;
|
|
2883
|
+
} else if (options.trim !== true) {
|
|
2884
|
+
throw new Error(
|
|
2885
|
+
`Invalid Option: trim must be a boolean, got ${JSON.stringify(options.trim)}`,
|
|
2886
|
+
);
|
|
2887
|
+
}
|
|
2888
|
+
// Normalize options `trim`, `ltrim` and `rtrim`
|
|
2889
|
+
if (options.trim === true && opts.ltrim !== false) {
|
|
2890
|
+
options.ltrim = true;
|
|
2891
|
+
} else if (options.ltrim !== true) {
|
|
2892
|
+
options.ltrim = false;
|
|
2893
|
+
}
|
|
2894
|
+
if (options.trim === true && opts.rtrim !== false) {
|
|
2895
|
+
options.rtrim = true;
|
|
2896
|
+
} else if (options.rtrim !== true) {
|
|
2897
|
+
options.rtrim = false;
|
|
2898
|
+
}
|
|
2899
|
+
// Normalize option `to`
|
|
2900
|
+
if (options.to === undefined || options.to === null) {
|
|
2901
|
+
options.to = -1;
|
|
2902
|
+
} else if (options.to !== -1) {
|
|
2903
|
+
if (typeof options.to === "string" && /\d+/.test(options.to)) {
|
|
2904
|
+
options.to = parseInt(options.to);
|
|
2905
|
+
}
|
|
2906
|
+
if (Number.isInteger(options.to)) {
|
|
2907
|
+
if (options.to <= 0) {
|
|
2908
|
+
throw new Error(
|
|
2909
|
+
`Invalid Option: to must be a positive integer greater than 0, got ${JSON.stringify(opts.to)}`,
|
|
2910
|
+
);
|
|
2911
|
+
}
|
|
2912
|
+
} else {
|
|
2913
|
+
throw new Error(
|
|
2914
|
+
`Invalid Option: to must be an integer, got ${JSON.stringify(opts.to)}`,
|
|
2915
|
+
);
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
// Normalize option `to_line`
|
|
2919
|
+
if (options.to_line === undefined || options.to_line === null) {
|
|
2920
|
+
options.to_line = -1;
|
|
2921
|
+
} else if (options.to_line !== -1) {
|
|
2922
|
+
if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
|
|
2923
|
+
options.to_line = parseInt(options.to_line);
|
|
2924
|
+
}
|
|
2925
|
+
if (Number.isInteger(options.to_line)) {
|
|
2926
|
+
if (options.to_line <= 0) {
|
|
2927
|
+
throw new Error(
|
|
2928
|
+
`Invalid Option: to_line must be a positive integer greater than 0, got ${JSON.stringify(opts.to_line)}`,
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
} else {
|
|
2932
|
+
throw new Error(
|
|
2933
|
+
`Invalid Option: to_line must be an integer, got ${JSON.stringify(opts.to_line)}`,
|
|
2934
|
+
);
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
return options;
|
|
2938
|
+
};
|
|
2939
|
+
|
|
2940
|
+
// Discussed in [issue #400](https://github.com/adaltas/node-csv/issues/400)
|
|
2941
|
+
// See https://github.com/python/cpython/blob/ea1b1c579f600cc85d145c60862b2e6b98701b24/Lib/csv.py#L349
|
|
2942
|
+
const delimiter_discover = function (records, options) {
|
|
2943
|
+
// Normalize the configuration
|
|
2944
|
+
if (!options) {
|
|
2945
|
+
({ delimiter_auto: options } = normalize_options({ delimiter_auto: true }));
|
|
2946
|
+
}
|
|
2947
|
+
// Convert String to Buffer
|
|
2948
|
+
if (typeof records === "string") {
|
|
2949
|
+
records = Buffer.from(records);
|
|
2950
|
+
}
|
|
2951
|
+
// Convert Buffer to an array of records
|
|
2952
|
+
if (isBuffer(records)) {
|
|
2953
|
+
records = ((data) => {
|
|
2954
|
+
const records = [];
|
|
2955
|
+
const parser = transform({ delimiter: [] });
|
|
2956
|
+
const push = (record) => records.push(record);
|
|
2957
|
+
const close = () => {};
|
|
2958
|
+
const error = parser.parse(data, true, push, close);
|
|
2959
|
+
if (error !== undefined) throw error;
|
|
2960
|
+
return records;
|
|
2961
|
+
})(records);
|
|
2962
|
+
}
|
|
2963
|
+
// Info array initialization, 127 entries, one per char code
|
|
2964
|
+
const info = Array(127)
|
|
2965
|
+
.fill()
|
|
2966
|
+
.map(() => ({ lines: [] }));
|
|
2967
|
+
// Traverse each records, count occurences per char code
|
|
2968
|
+
records.map(([record], line) => {
|
|
2969
|
+
for (let i = 0, l = record.length; i < l; i++) {
|
|
2970
|
+
// Count the character frequency
|
|
2971
|
+
const code = record.charCodeAt(i);
|
|
2972
|
+
if (info[code].lines[line] === undefined) info[code].lines[line] = 0;
|
|
2973
|
+
info[code].lines[line]++;
|
|
2974
|
+
}
|
|
2975
|
+
});
|
|
2976
|
+
// Traverse each char code, compute the score
|
|
2977
|
+
info.map((info, i) => {
|
|
2978
|
+
info.char_code = i;
|
|
2979
|
+
info.std = std(info.lines);
|
|
2980
|
+
info.total = info.lines.reduce((acc, val) => acc + val, 0);
|
|
2981
|
+
info.preferred = !!options.preferred[i];
|
|
2982
|
+
info.score = options.score(info, options);
|
|
2983
|
+
});
|
|
2984
|
+
// Extract the dominant character
|
|
2985
|
+
const result = info.reduce(
|
|
2986
|
+
(acc, info) => (acc.score > info.score ? acc : info),
|
|
2987
|
+
{},
|
|
2988
|
+
);
|
|
2989
|
+
return String.fromCharCode(result.char_code);
|
|
2990
|
+
};
|
|
2991
|
+
|
|
2992
|
+
const std = function (array) {
|
|
2993
|
+
const n = array.length;
|
|
2994
|
+
if (n === 0) return 0;
|
|
2995
|
+
const mean = array.reduce((a, b) => a + b) / n;
|
|
2996
|
+
return Math.sqrt(
|
|
2997
|
+
array.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n,
|
|
2998
|
+
);
|
|
2999
|
+
};
|
|
3000
|
+
|
|
3001
|
+
const isRecordEmpty = function (record) {
|
|
3002
|
+
return record.every(
|
|
3003
|
+
(field) =>
|
|
3004
|
+
field == null || (field.toString && field.toString().trim() === ""),
|
|
3005
|
+
);
|
|
3006
|
+
};
|
|
3007
|
+
|
|
3008
|
+
const cr = 13; // `\r`, carriage return, 0x0D in hexadécimal, 13 in decimal
|
|
3009
|
+
const nl = 10; // `\n`, newline, 0x0A in hexadecimal, 10 in decimal
|
|
3010
|
+
|
|
3011
|
+
const boms = {
|
|
3012
|
+
// Note, the following are equals:
|
|
3013
|
+
// Buffer.from("\ufeff")
|
|
3014
|
+
// Buffer.from([239, 187, 191])
|
|
3015
|
+
// Buffer.from('EFBBBF', 'hex')
|
|
3016
|
+
utf8: Buffer.from([239, 187, 191]),
|
|
3017
|
+
// Note, the following are equals:
|
|
3018
|
+
// Buffer.from "\ufeff", 'utf16le
|
|
3019
|
+
// Buffer.from([255, 254])
|
|
3020
|
+
utf16le: Buffer.from([255, 254]),
|
|
3021
|
+
};
|
|
3022
|
+
|
|
3023
|
+
const transform = function (original_options = {}) {
|
|
3024
|
+
const info = {
|
|
3025
|
+
bytes: 0,
|
|
3026
|
+
bytes_records: 0,
|
|
3027
|
+
comment_lines: 0,
|
|
3028
|
+
empty_lines: 0,
|
|
3029
|
+
invalid_field_length: 0,
|
|
3030
|
+
lines: 1,
|
|
3031
|
+
records: 0,
|
|
3032
|
+
};
|
|
3033
|
+
const options = normalize_options(original_options);
|
|
3034
|
+
return {
|
|
3035
|
+
info: info,
|
|
3036
|
+
original_options: original_options,
|
|
3037
|
+
options: options,
|
|
3038
|
+
state: init_state(options),
|
|
3039
|
+
__needMoreData: function (i, bufLen, end) {
|
|
3040
|
+
if (end) return false;
|
|
3041
|
+
const { encoding, escape, quote } = this.options;
|
|
3042
|
+
const { quoting, needMoreDataSize, recordDelimiterMaxLength } =
|
|
3043
|
+
this.state;
|
|
3044
|
+
const numOfCharLeft = bufLen - i - 1;
|
|
3045
|
+
const requiredLength = Math.max(
|
|
3046
|
+
needMoreDataSize,
|
|
3047
|
+
// Skip if the remaining buffer smaller than record delimiter
|
|
3048
|
+
// If "record_delimiter" is yet to be discovered:
|
|
3049
|
+
// 1. It is equals to `[]` and "recordDelimiterMaxLength" equals `0`
|
|
3050
|
+
// 2. We set the length to windows line ending in the current encoding
|
|
3051
|
+
// Note, that encoding is known from user or bom discovery at that point
|
|
3052
|
+
// recordDelimiterMaxLength,
|
|
3053
|
+
recordDelimiterMaxLength === 0
|
|
3054
|
+
? Buffer.from("\r\n", encoding).length
|
|
3055
|
+
: recordDelimiterMaxLength,
|
|
3056
|
+
// Skip if remaining buffer can be an escaped quote
|
|
3057
|
+
quoting ? (escape === null ? 0 : escape.length) + quote.length : 0,
|
|
3058
|
+
// Skip if remaining buffer can be record delimiter following the closing quote
|
|
3059
|
+
quoting ? quote.length + recordDelimiterMaxLength : 0,
|
|
3060
|
+
);
|
|
3061
|
+
return numOfCharLeft < requiredLength;
|
|
3062
|
+
},
|
|
3063
|
+
// Central parser implementation
|
|
3064
|
+
parse: function (nextBuf, end, push, close) {
|
|
3065
|
+
const {
|
|
3066
|
+
bom,
|
|
3067
|
+
comment_no_infix,
|
|
3068
|
+
delimiter_auto,
|
|
3069
|
+
encoding,
|
|
3070
|
+
from_line,
|
|
3071
|
+
ltrim,
|
|
3072
|
+
max_record_size,
|
|
3073
|
+
raw,
|
|
3074
|
+
relax_quotes,
|
|
3075
|
+
rtrim,
|
|
3076
|
+
skip_empty_lines,
|
|
3077
|
+
to,
|
|
3078
|
+
to_line,
|
|
3079
|
+
} = this.options;
|
|
3080
|
+
let { comment, escape, quote, record_delimiter } = this.options;
|
|
3081
|
+
const {
|
|
3082
|
+
bomSkipped,
|
|
3083
|
+
delimiterDiscovered,
|
|
3084
|
+
delimiterBufPrevious,
|
|
3085
|
+
rawBuffer,
|
|
3086
|
+
escapeIsQuote,
|
|
3087
|
+
} = this.state;
|
|
3088
|
+
// Automatic delimiter discovery
|
|
3089
|
+
if (!delimiterDiscovered && delimiter_auto) {
|
|
3090
|
+
let delimiterBuf;
|
|
3091
|
+
if (delimiterBufPrevious === undefined) {
|
|
3092
|
+
delimiterBuf = nextBuf;
|
|
3093
|
+
} else if (
|
|
3094
|
+
delimiterBufPrevious !== undefined &&
|
|
3095
|
+
nextBuf === undefined
|
|
3096
|
+
) {
|
|
3097
|
+
delimiterBuf = delimiterBufPrevious;
|
|
3098
|
+
} else {
|
|
3099
|
+
delimiterBuf = Buffer.concat([delimiterBufPrevious, nextBuf]);
|
|
3100
|
+
}
|
|
3101
|
+
// Ensure that nextBuf is not concatenated a second time during buffer reconciliation
|
|
3102
|
+
nextBuf = undefined;
|
|
3103
|
+
// this.delimiterBufPrevious = delimiterBuf;
|
|
3104
|
+
if (end || delimiterBuf.length > delimiter_auto.size) {
|
|
3105
|
+
this.options.delimiter = [
|
|
3106
|
+
Buffer.from(
|
|
3107
|
+
delimiter_discover(delimiterBuf, this.options.delimiter_auto),
|
|
3108
|
+
),
|
|
3109
|
+
];
|
|
3110
|
+
this.state.previousBuf = delimiterBuf;
|
|
3111
|
+
this.state.delimiterBufPrevious = undefined;
|
|
3112
|
+
this.state.delimiterDiscovered = true;
|
|
3113
|
+
} else {
|
|
3114
|
+
this.state.delimiterBufPrevious = delimiterBuf;
|
|
3115
|
+
return;
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
// Previous buffers reconciliation
|
|
3119
|
+
const { previousBuf } = this.state;
|
|
3120
|
+
let buf;
|
|
3121
|
+
if (previousBuf === undefined) {
|
|
3122
|
+
if (nextBuf === undefined) {
|
|
3123
|
+
// Handle empty string
|
|
3124
|
+
close();
|
|
3125
|
+
return;
|
|
3126
|
+
} else {
|
|
3127
|
+
buf = nextBuf;
|
|
3128
|
+
}
|
|
3129
|
+
} else if (previousBuf !== undefined && nextBuf === undefined) {
|
|
3130
|
+
buf = previousBuf;
|
|
3131
|
+
} else {
|
|
3132
|
+
buf = Buffer.concat([previousBuf, nextBuf]);
|
|
3133
|
+
}
|
|
3134
|
+
// Handle UTF BOM
|
|
3135
|
+
if (bomSkipped === false) {
|
|
3136
|
+
if (bom === false) {
|
|
3137
|
+
this.state.bomSkipped = true;
|
|
3138
|
+
} else if (buf.length < 3) {
|
|
3139
|
+
// No enough data
|
|
3140
|
+
if (end === false) {
|
|
3141
|
+
// Wait for more data
|
|
3142
|
+
this.state.previousBuf = buf;
|
|
3143
|
+
return;
|
|
3144
|
+
}
|
|
3145
|
+
} else {
|
|
3146
|
+
for (const encoding in boms) {
|
|
3147
|
+
if (boms[encoding].compare(buf, 0, boms[encoding].length) === 0) {
|
|
3148
|
+
// Skip BOM
|
|
3149
|
+
const bomLength = boms[encoding].length;
|
|
3150
|
+
this.state.bufBytesStart += bomLength;
|
|
3151
|
+
buf = buf.slice(bomLength);
|
|
3152
|
+
// Renormalize original options with the new encoding
|
|
3153
|
+
const options = normalize_options({
|
|
3154
|
+
...this.original_options,
|
|
3155
|
+
encoding: encoding,
|
|
3156
|
+
});
|
|
3157
|
+
// Properties are merged with the existing options instance
|
|
3158
|
+
for (const key in options) {
|
|
3159
|
+
this.options[key] = options[key];
|
|
3160
|
+
}
|
|
3161
|
+
// Options will re-evaluate the Buffer with the new encoding
|
|
3162
|
+
({ comment, escape, quote } = this.options);
|
|
3163
|
+
break;
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
this.state.bomSkipped = true;
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
const bufLen = buf.length;
|
|
3170
|
+
let pos;
|
|
3171
|
+
for (pos = 0; pos < bufLen; pos++) {
|
|
3172
|
+
// Ensure we get enough space to look ahead
|
|
3173
|
+
// There should be a way to move this out of the loop
|
|
3174
|
+
if (this.__needMoreData(pos, bufLen, end)) {
|
|
3175
|
+
break;
|
|
3176
|
+
}
|
|
3177
|
+
if (this.state.wasRowDelimiter === true) {
|
|
3178
|
+
this.info.lines++;
|
|
3179
|
+
this.state.wasRowDelimiter = false;
|
|
3180
|
+
}
|
|
3181
|
+
if (to_line !== -1 && this.info.lines > to_line) {
|
|
3182
|
+
this.state.stop = true;
|
|
3183
|
+
close();
|
|
3184
|
+
return;
|
|
3185
|
+
}
|
|
3186
|
+
// Auto discovery of record_delimiter, unix, mac and windows supported
|
|
3187
|
+
if (this.state.quoting === false && record_delimiter.length === 0) {
|
|
3188
|
+
const record_delimiterCount = this.__autoDiscoverRecordDelimiter(
|
|
3189
|
+
buf,
|
|
3190
|
+
pos,
|
|
3191
|
+
);
|
|
3192
|
+
if (record_delimiterCount) {
|
|
3193
|
+
record_delimiter = this.options.record_delimiter;
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
const chr = buf[pos];
|
|
3197
|
+
if (raw === true) {
|
|
3198
|
+
rawBuffer.append(chr);
|
|
3199
|
+
}
|
|
3200
|
+
if (
|
|
3201
|
+
(chr === cr || chr === nl) &&
|
|
3202
|
+
this.state.wasRowDelimiter === false
|
|
3203
|
+
) {
|
|
3204
|
+
this.state.wasRowDelimiter = true;
|
|
3205
|
+
}
|
|
3206
|
+
// Previous char was a valid escape char
|
|
3207
|
+
// treat the current char as a regular char
|
|
3208
|
+
if (this.state.escaping === true) {
|
|
3209
|
+
this.state.escaping = false;
|
|
3210
|
+
} else {
|
|
3211
|
+
// Escape is only active inside quoted fields
|
|
3212
|
+
// We are quoting, the char is an escape chr and there is a chr to escape
|
|
3213
|
+
// if(escape !== null && this.state.quoting === true && chr === escape && pos + 1 < bufLen){
|
|
3214
|
+
if (
|
|
3215
|
+
escape !== null &&
|
|
3216
|
+
this.state.quoting === true &&
|
|
3217
|
+
this.__isEscape(buf, pos, chr) &&
|
|
3218
|
+
pos + escape.length < bufLen
|
|
3219
|
+
) {
|
|
3220
|
+
if (escapeIsQuote) {
|
|
3221
|
+
if (this.__isQuote(buf, pos + escape.length)) {
|
|
3222
|
+
this.state.escaping = true;
|
|
3223
|
+
pos += escape.length - 1;
|
|
3224
|
+
continue;
|
|
3225
|
+
}
|
|
3226
|
+
} else {
|
|
3227
|
+
this.state.escaping = true;
|
|
3228
|
+
pos += escape.length - 1;
|
|
3229
|
+
continue;
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
// Not currently escaping and chr is a quote
|
|
3233
|
+
// TODO: need to compare bytes instead of single char
|
|
3234
|
+
if (this.state.commenting === false && this.__isQuote(buf, pos)) {
|
|
3235
|
+
if (this.state.quoting === true) {
|
|
3236
|
+
const nextChr = buf[pos + quote.length];
|
|
3237
|
+
const isNextChrTrimable =
|
|
3238
|
+
rtrim && this.__isCharTrimable(buf, pos + quote.length);
|
|
3239
|
+
const isNextChrComment =
|
|
3240
|
+
comment !== null &&
|
|
3241
|
+
this.__compareBytes(comment, buf, pos + quote.length, nextChr);
|
|
3242
|
+
const isNextChrDelimiter = this.__isDelimiter(
|
|
3243
|
+
buf,
|
|
3244
|
+
pos + quote.length,
|
|
3245
|
+
nextChr,
|
|
3246
|
+
);
|
|
3247
|
+
const isNextChrRecordDelimiter =
|
|
3248
|
+
record_delimiter.length === 0
|
|
3249
|
+
? this.__autoDiscoverRecordDelimiter(buf, pos + quote.length)
|
|
3250
|
+
: this.__isRecordDelimiter(nextChr, buf, pos + quote.length);
|
|
3251
|
+
// Escape a quote
|
|
3252
|
+
// Treat next char as a regular character
|
|
3253
|
+
if (
|
|
3254
|
+
escape !== null &&
|
|
3255
|
+
this.__isEscape(buf, pos, chr) &&
|
|
3256
|
+
this.__isQuote(buf, pos + escape.length)
|
|
3257
|
+
) {
|
|
3258
|
+
pos += escape.length - 1;
|
|
3259
|
+
} else if (
|
|
3260
|
+
!nextChr ||
|
|
3261
|
+
isNextChrDelimiter ||
|
|
3262
|
+
isNextChrRecordDelimiter ||
|
|
3263
|
+
isNextChrComment ||
|
|
3264
|
+
isNextChrTrimable
|
|
3265
|
+
) {
|
|
3266
|
+
this.state.quoting = false;
|
|
3267
|
+
this.state.wasQuoting = true;
|
|
3268
|
+
pos += quote.length - 1;
|
|
3269
|
+
continue;
|
|
3270
|
+
} else if (relax_quotes === false) {
|
|
3271
|
+
const err = this.__error(
|
|
3272
|
+
new CsvError(
|
|
3273
|
+
"CSV_INVALID_CLOSING_QUOTE",
|
|
3274
|
+
[
|
|
3275
|
+
"Invalid Closing Quote:",
|
|
3276
|
+
`got "${String.fromCharCode(nextChr)}"`,
|
|
3277
|
+
`at line ${this.info.lines}`,
|
|
3278
|
+
"instead of delimiter, record delimiter, trimable character",
|
|
3279
|
+
"(if activated) or comment",
|
|
3280
|
+
],
|
|
3281
|
+
this.options,
|
|
3282
|
+
this.__infoField(),
|
|
3283
|
+
),
|
|
3284
|
+
);
|
|
3285
|
+
if (err !== undefined) return err;
|
|
3286
|
+
} else {
|
|
3287
|
+
this.state.quoting = false;
|
|
3288
|
+
this.state.wasQuoting = true;
|
|
3289
|
+
this.state.field.prepend(quote);
|
|
3290
|
+
pos += quote.length - 1;
|
|
3291
|
+
}
|
|
3292
|
+
} else {
|
|
3293
|
+
if (this.state.field.length !== 0) {
|
|
3294
|
+
// In relax_quotes mode, treat opening quote preceded by chrs as regular
|
|
3295
|
+
if (relax_quotes === false) {
|
|
3296
|
+
const info = this.__infoField();
|
|
3297
|
+
const bom = Object.keys(boms)
|
|
3298
|
+
.map((b) =>
|
|
3299
|
+
boms[b].equals(this.state.field.toString()) ? b : false,
|
|
3300
|
+
)
|
|
3301
|
+
.filter(Boolean)[0];
|
|
3302
|
+
const err = this.__error(
|
|
3303
|
+
new CsvError(
|
|
3304
|
+
"INVALID_OPENING_QUOTE",
|
|
3305
|
+
[
|
|
3306
|
+
"Invalid Opening Quote:",
|
|
3307
|
+
`a quote is found on field ${JSON.stringify(info.column)} at line ${info.lines}, value is ${JSON.stringify(this.state.field.toString(encoding))}`,
|
|
3308
|
+
bom ? `(${bom} bom)` : undefined,
|
|
3309
|
+
],
|
|
3310
|
+
this.options,
|
|
3311
|
+
info,
|
|
3312
|
+
{
|
|
3313
|
+
field: this.state.field,
|
|
3314
|
+
},
|
|
3315
|
+
),
|
|
3316
|
+
);
|
|
3317
|
+
if (err !== undefined) return err;
|
|
3318
|
+
}
|
|
3319
|
+
} else {
|
|
3320
|
+
this.state.quoting = true;
|
|
3321
|
+
pos += quote.length - 1;
|
|
3322
|
+
continue;
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
if (this.state.quoting === false) {
|
|
3327
|
+
const recordDelimiterLength = this.__isRecordDelimiter(
|
|
3328
|
+
chr,
|
|
3329
|
+
buf,
|
|
3330
|
+
pos,
|
|
3331
|
+
);
|
|
3332
|
+
if (recordDelimiterLength !== 0) {
|
|
3333
|
+
// Do not emit comments which take a full line
|
|
3334
|
+
const skipCommentLine =
|
|
3335
|
+
this.state.commenting &&
|
|
3336
|
+
this.state.wasQuoting === false &&
|
|
3337
|
+
this.state.record.length === 0 &&
|
|
3338
|
+
this.state.field.length === 0;
|
|
3339
|
+
if (skipCommentLine) {
|
|
3340
|
+
this.info.comment_lines++;
|
|
3341
|
+
// Skip full comment line
|
|
3342
|
+
} else {
|
|
3343
|
+
// Activate records emission if above from_line
|
|
3344
|
+
if (
|
|
3345
|
+
this.state.enabled === false &&
|
|
3346
|
+
this.info.lines +
|
|
3347
|
+
(this.state.wasRowDelimiter === true ? 1 : 0) >=
|
|
3348
|
+
from_line
|
|
3349
|
+
) {
|
|
3350
|
+
this.state.enabled = true;
|
|
3351
|
+
this.__resetField();
|
|
3352
|
+
this.__resetRecord();
|
|
3353
|
+
pos += recordDelimiterLength - 1;
|
|
3354
|
+
continue;
|
|
3355
|
+
}
|
|
3356
|
+
// Skip if line is empty and skip_empty_lines activated
|
|
3357
|
+
if (
|
|
3358
|
+
skip_empty_lines === true &&
|
|
3359
|
+
this.state.wasQuoting === false &&
|
|
3360
|
+
this.state.record.length === 0 &&
|
|
3361
|
+
this.state.field.length === 0
|
|
3362
|
+
) {
|
|
3363
|
+
this.info.empty_lines++;
|
|
3364
|
+
pos += recordDelimiterLength - 1;
|
|
3365
|
+
continue;
|
|
3366
|
+
}
|
|
3367
|
+
this.info.bytes = this.state.bufBytesStart + pos;
|
|
3368
|
+
const errField = this.__onField();
|
|
3369
|
+
if (errField !== undefined) return errField;
|
|
3370
|
+
this.info.bytes =
|
|
3371
|
+
this.state.bufBytesStart + pos + recordDelimiterLength;
|
|
3372
|
+
const errRecord = this.__onRecord(push);
|
|
3373
|
+
if (errRecord !== undefined) return errRecord;
|
|
3374
|
+
if (to !== -1 && this.info.records >= to) {
|
|
3375
|
+
this.state.stop = true;
|
|
3376
|
+
close();
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
this.state.commenting = false;
|
|
3381
|
+
pos += recordDelimiterLength - 1;
|
|
3382
|
+
continue;
|
|
3383
|
+
}
|
|
3384
|
+
if (this.state.commenting) {
|
|
3385
|
+
continue;
|
|
3386
|
+
}
|
|
3387
|
+
if (
|
|
3388
|
+
comment !== null &&
|
|
3389
|
+
(comment_no_infix === false ||
|
|
3390
|
+
(this.state.record.length === 0 &&
|
|
3391
|
+
this.state.field.length === 0))
|
|
3392
|
+
) {
|
|
3393
|
+
const commentCount = this.__compareBytes(comment, buf, pos, chr);
|
|
3394
|
+
if (commentCount !== 0) {
|
|
3395
|
+
this.state.commenting = true;
|
|
3396
|
+
continue;
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3399
|
+
const delimiterLength = this.__isDelimiter(buf, pos, chr);
|
|
3400
|
+
if (delimiterLength !== 0) {
|
|
3401
|
+
this.info.bytes = this.state.bufBytesStart + pos;
|
|
3402
|
+
const errField = this.__onField();
|
|
3403
|
+
if (errField !== undefined) return errField;
|
|
3404
|
+
pos += delimiterLength - 1;
|
|
3405
|
+
continue;
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3409
|
+
if (this.state.commenting === false) {
|
|
3410
|
+
if (
|
|
3411
|
+
max_record_size !== 0 &&
|
|
3412
|
+
this.state.record_length + this.state.field.length > max_record_size
|
|
3413
|
+
) {
|
|
3414
|
+
return this.__error(
|
|
3415
|
+
new CsvError(
|
|
3416
|
+
"CSV_MAX_RECORD_SIZE",
|
|
3417
|
+
[
|
|
3418
|
+
"Max Record Size:",
|
|
3419
|
+
"record exceed the maximum number of tolerated bytes",
|
|
3420
|
+
`of ${max_record_size}`,
|
|
3421
|
+
`at line ${this.info.lines}`,
|
|
3422
|
+
],
|
|
3423
|
+
this.options,
|
|
3424
|
+
this.__infoField(),
|
|
3425
|
+
),
|
|
3426
|
+
);
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
const lappend =
|
|
3430
|
+
ltrim === false ||
|
|
3431
|
+
this.state.quoting === true ||
|
|
3432
|
+
this.state.field.length !== 0 ||
|
|
3433
|
+
!this.__isCharTrimable(buf, pos);
|
|
3434
|
+
// rtrim in non quoting is handle in __onField
|
|
3435
|
+
const rappend = rtrim === false || this.state.wasQuoting === false;
|
|
3436
|
+
if (lappend === true && rappend === true) {
|
|
3437
|
+
this.state.field.append(chr);
|
|
3438
|
+
} else if (rtrim === true && !this.__isCharTrimable(buf, pos)) {
|
|
3439
|
+
return this.__error(
|
|
3440
|
+
new CsvError(
|
|
3441
|
+
"CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE",
|
|
3442
|
+
[
|
|
3443
|
+
"Invalid Closing Quote:",
|
|
3444
|
+
"found non trimable byte after quote",
|
|
3445
|
+
`at line ${this.info.lines}`,
|
|
3446
|
+
],
|
|
3447
|
+
this.options,
|
|
3448
|
+
this.__infoField(),
|
|
3449
|
+
),
|
|
3450
|
+
);
|
|
3451
|
+
} else {
|
|
3452
|
+
if (lappend === false) {
|
|
3453
|
+
pos += this.__isCharTrimable(buf, pos) - 1;
|
|
3454
|
+
}
|
|
3455
|
+
continue;
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
if (end === true) {
|
|
3459
|
+
// Ensure we are not ending in a quoting state
|
|
3460
|
+
if (this.state.quoting === true) {
|
|
3461
|
+
const err = this.__error(
|
|
3462
|
+
new CsvError(
|
|
3463
|
+
"CSV_QUOTE_NOT_CLOSED",
|
|
3464
|
+
[
|
|
3465
|
+
"Quote Not Closed:",
|
|
3466
|
+
`the parsing is finished with an opening quote at line ${this.info.lines}`,
|
|
3467
|
+
],
|
|
3468
|
+
this.options,
|
|
3469
|
+
this.__infoField(),
|
|
3470
|
+
),
|
|
3471
|
+
);
|
|
3472
|
+
if (err !== undefined) return err;
|
|
3473
|
+
} else {
|
|
3474
|
+
// Skip last line if it has no characters
|
|
3475
|
+
if (
|
|
3476
|
+
this.state.wasQuoting === true ||
|
|
3477
|
+
this.state.record.length !== 0 ||
|
|
3478
|
+
this.state.field.length !== 0
|
|
3479
|
+
) {
|
|
3480
|
+
this.info.bytes = this.state.bufBytesStart + pos;
|
|
3481
|
+
const errField = this.__onField();
|
|
3482
|
+
if (errField !== undefined) return errField;
|
|
3483
|
+
const errRecord = this.__onRecord(push);
|
|
3484
|
+
if (errRecord !== undefined) return errRecord;
|
|
3485
|
+
} else if (this.state.wasRowDelimiter === true) {
|
|
3486
|
+
this.info.empty_lines++;
|
|
3487
|
+
} else if (this.state.commenting === true) {
|
|
3488
|
+
this.info.comment_lines++;
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
} else {
|
|
3492
|
+
this.state.bufBytesStart += pos;
|
|
3493
|
+
this.state.previousBuf = buf.slice(pos);
|
|
3494
|
+
}
|
|
3495
|
+
if (this.state.wasRowDelimiter === true) {
|
|
3496
|
+
this.info.lines++;
|
|
3497
|
+
this.state.wasRowDelimiter = false;
|
|
3498
|
+
}
|
|
3499
|
+
},
|
|
3500
|
+
__onRecord: function (push) {
|
|
3501
|
+
const {
|
|
3502
|
+
columns,
|
|
3503
|
+
group_columns_by_name,
|
|
3504
|
+
encoding,
|
|
3505
|
+
info,
|
|
3506
|
+
from,
|
|
3507
|
+
relax_column_count,
|
|
3508
|
+
relax_column_count_less,
|
|
3509
|
+
relax_column_count_more,
|
|
3510
|
+
raw,
|
|
3511
|
+
skip_records_with_empty_values,
|
|
3512
|
+
} = this.options;
|
|
3513
|
+
const { enabled, record } = this.state;
|
|
3514
|
+
if (enabled === false) {
|
|
3515
|
+
return this.__resetRecord();
|
|
3516
|
+
}
|
|
3517
|
+
// Convert the first line into column names
|
|
3518
|
+
const recordLength = record.length;
|
|
3519
|
+
if (columns === true) {
|
|
3520
|
+
if (skip_records_with_empty_values === true && isRecordEmpty(record)) {
|
|
3521
|
+
this.__resetRecord();
|
|
3522
|
+
return;
|
|
3523
|
+
}
|
|
3524
|
+
return this.__firstLineToColumns(record);
|
|
3525
|
+
}
|
|
3526
|
+
if (columns === false && this.info.records === 0) {
|
|
3527
|
+
this.state.expectedRecordLength = recordLength;
|
|
3528
|
+
}
|
|
3529
|
+
if (recordLength !== this.state.expectedRecordLength) {
|
|
3530
|
+
const err =
|
|
3531
|
+
columns === false
|
|
3532
|
+
? new CsvError(
|
|
3533
|
+
"CSV_RECORD_INCONSISTENT_FIELDS_LENGTH",
|
|
3534
|
+
[
|
|
3535
|
+
"Invalid Record Length:",
|
|
3536
|
+
`expect ${this.state.expectedRecordLength},`,
|
|
3537
|
+
`got ${recordLength} on line ${this.info.lines}`,
|
|
3538
|
+
],
|
|
3539
|
+
this.options,
|
|
3540
|
+
this.__infoField(),
|
|
3541
|
+
{
|
|
3542
|
+
record: record,
|
|
3543
|
+
},
|
|
3544
|
+
)
|
|
3545
|
+
: new CsvError(
|
|
3546
|
+
"CSV_RECORD_INCONSISTENT_COLUMNS",
|
|
3547
|
+
[
|
|
3548
|
+
"Invalid Record Length:",
|
|
3549
|
+
`columns length is ${columns.length},`, // rename columns
|
|
3550
|
+
`got ${recordLength} on line ${this.info.lines}`,
|
|
3551
|
+
],
|
|
3552
|
+
this.options,
|
|
3553
|
+
this.__infoField(),
|
|
3554
|
+
{
|
|
3555
|
+
record: record,
|
|
3556
|
+
},
|
|
3557
|
+
);
|
|
3558
|
+
if (
|
|
3559
|
+
relax_column_count === true ||
|
|
3560
|
+
(relax_column_count_less === true &&
|
|
3561
|
+
recordLength < this.state.expectedRecordLength) ||
|
|
3562
|
+
(relax_column_count_more === true &&
|
|
3563
|
+
recordLength > this.state.expectedRecordLength)
|
|
3564
|
+
) {
|
|
3565
|
+
this.info.invalid_field_length++;
|
|
3566
|
+
this.state.error = err;
|
|
3567
|
+
// Error is undefined with skip_records_with_error
|
|
3568
|
+
} else {
|
|
3569
|
+
const finalErr = this.__error(err);
|
|
3570
|
+
if (finalErr) return finalErr;
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
if (skip_records_with_empty_values === true && isRecordEmpty(record)) {
|
|
3574
|
+
this.__resetRecord();
|
|
3575
|
+
return;
|
|
3576
|
+
}
|
|
3577
|
+
if (this.state.recordHasError === true) {
|
|
3578
|
+
this.__resetRecord();
|
|
3579
|
+
this.state.recordHasError = false;
|
|
3580
|
+
return;
|
|
3581
|
+
}
|
|
3582
|
+
this.info.records++;
|
|
3583
|
+
if (from === 1 || this.info.records >= from) {
|
|
3584
|
+
const { objname } = this.options;
|
|
3585
|
+
// With columns, records are object
|
|
3586
|
+
if (columns !== false) {
|
|
3587
|
+
const obj = {};
|
|
3588
|
+
// Transform record array to an object
|
|
3589
|
+
for (let i = 0, l = record.length; i < l; i++) {
|
|
3590
|
+
if (columns[i] === undefined || columns[i].disabled) continue;
|
|
3591
|
+
// Turn duplicate columns into an array
|
|
3592
|
+
if (
|
|
3593
|
+
group_columns_by_name === true &&
|
|
3594
|
+
obj[columns[i].name] !== undefined
|
|
3595
|
+
) {
|
|
3596
|
+
if (Array.isArray(obj[columns[i].name])) {
|
|
3597
|
+
obj[columns[i].name] = obj[columns[i].name].concat(record[i]);
|
|
3598
|
+
} else {
|
|
3599
|
+
obj[columns[i].name] = [obj[columns[i].name], record[i]];
|
|
3600
|
+
}
|
|
3601
|
+
} else {
|
|
3602
|
+
obj[columns[i].name] = record[i];
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
// Without objname (default)
|
|
3606
|
+
if (raw === true || info === true) {
|
|
3607
|
+
const extRecord = Object.assign(
|
|
3608
|
+
{ record: obj },
|
|
3609
|
+
raw === true
|
|
3610
|
+
? { raw: this.state.rawBuffer.toString(encoding) }
|
|
3611
|
+
: {},
|
|
3612
|
+
info === true ? { info: this.__infoRecord() } : {},
|
|
3613
|
+
);
|
|
3614
|
+
const err = this.__push(
|
|
3615
|
+
objname === undefined ? extRecord : [obj[objname], extRecord],
|
|
3616
|
+
push,
|
|
3617
|
+
);
|
|
3618
|
+
if (err) {
|
|
3619
|
+
return err;
|
|
3620
|
+
}
|
|
3621
|
+
} else {
|
|
3622
|
+
const err = this.__push(
|
|
3623
|
+
objname === undefined ? obj : [obj[objname], obj],
|
|
3624
|
+
push,
|
|
3625
|
+
);
|
|
3626
|
+
if (err) {
|
|
3627
|
+
return err;
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
// Without columns, records are array
|
|
3631
|
+
} else {
|
|
3632
|
+
if (raw === true || info === true) {
|
|
3633
|
+
const extRecord = Object.assign(
|
|
3634
|
+
{ record: record },
|
|
3635
|
+
raw === true
|
|
3636
|
+
? { raw: this.state.rawBuffer.toString(encoding) }
|
|
3637
|
+
: {},
|
|
3638
|
+
info === true ? { info: this.__infoRecord() } : {},
|
|
3639
|
+
);
|
|
3640
|
+
const err = this.__push(
|
|
3641
|
+
objname === undefined ? extRecord : [record[objname], extRecord],
|
|
3642
|
+
push,
|
|
3643
|
+
);
|
|
3644
|
+
if (err) {
|
|
3645
|
+
return err;
|
|
3646
|
+
}
|
|
3647
|
+
} else {
|
|
3648
|
+
const err = this.__push(
|
|
3649
|
+
objname === undefined ? record : [record[objname], record],
|
|
3650
|
+
push,
|
|
3651
|
+
);
|
|
3652
|
+
if (err) {
|
|
3653
|
+
return err;
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
this.__resetRecord();
|
|
3659
|
+
},
|
|
3660
|
+
__firstLineToColumns: function (record) {
|
|
3661
|
+
const { firstLineToHeaders } = this.state;
|
|
3662
|
+
try {
|
|
3663
|
+
const headers =
|
|
3664
|
+
firstLineToHeaders === undefined
|
|
3665
|
+
? record
|
|
3666
|
+
: firstLineToHeaders.call(null, record);
|
|
3667
|
+
if (!Array.isArray(headers)) {
|
|
3668
|
+
return this.__error(
|
|
3669
|
+
new CsvError(
|
|
3670
|
+
"CSV_INVALID_COLUMN_MAPPING",
|
|
3671
|
+
[
|
|
3672
|
+
"Invalid Column Mapping:",
|
|
3673
|
+
"expect an array from column function,",
|
|
3674
|
+
`got ${JSON.stringify(headers)}`,
|
|
3675
|
+
],
|
|
3676
|
+
this.options,
|
|
3677
|
+
this.__infoField(),
|
|
3678
|
+
{
|
|
3679
|
+
headers: headers,
|
|
3680
|
+
},
|
|
3681
|
+
),
|
|
3682
|
+
);
|
|
3683
|
+
}
|
|
3684
|
+
const normalizedHeaders = normalize_columns_array(headers);
|
|
3685
|
+
this.state.expectedRecordLength = normalizedHeaders.length;
|
|
3686
|
+
this.options.columns = normalizedHeaders;
|
|
3687
|
+
this.__resetRecord();
|
|
3688
|
+
return;
|
|
3689
|
+
} catch (err) {
|
|
3690
|
+
return err;
|
|
3691
|
+
}
|
|
3692
|
+
},
|
|
3693
|
+
__resetRecord: function () {
|
|
3694
|
+
if (this.options.raw === true) {
|
|
3695
|
+
this.state.rawBuffer.reset();
|
|
3696
|
+
}
|
|
3697
|
+
this.state.error = undefined;
|
|
3698
|
+
this.state.record = [];
|
|
3699
|
+
this.state.record_length = 0;
|
|
3700
|
+
},
|
|
3701
|
+
__onField: function () {
|
|
3702
|
+
const { cast, encoding, rtrim, max_record_size } = this.options;
|
|
3703
|
+
const { enabled, wasQuoting } = this.state;
|
|
3704
|
+
// Short circuit for the from_line options
|
|
3705
|
+
if (enabled === false) {
|
|
3706
|
+
return this.__resetField();
|
|
3707
|
+
}
|
|
3708
|
+
let field = this.state.field.toString(encoding);
|
|
3709
|
+
if (rtrim === true && wasQuoting === false) {
|
|
3710
|
+
field = field.trimRight();
|
|
3711
|
+
}
|
|
3712
|
+
if (cast === true) {
|
|
3713
|
+
const [err, f] = this.__cast(field);
|
|
3714
|
+
if (err !== undefined) return err;
|
|
3715
|
+
field = f;
|
|
3716
|
+
}
|
|
3717
|
+
this.state.record.push(field);
|
|
3718
|
+
// Increment record length if record size must not exceed a limit
|
|
3719
|
+
if (max_record_size !== 0 && typeof field === "string") {
|
|
3720
|
+
this.state.record_length += field.length;
|
|
3721
|
+
}
|
|
3722
|
+
this.__resetField();
|
|
3723
|
+
},
|
|
3724
|
+
__resetField: function () {
|
|
3725
|
+
this.state.field.reset();
|
|
3726
|
+
this.state.wasQuoting = false;
|
|
3727
|
+
},
|
|
3728
|
+
__push: function (record, push) {
|
|
3729
|
+
const { on_record } = this.options;
|
|
3730
|
+
if (on_record !== undefined) {
|
|
3731
|
+
const info = this.__infoRecord();
|
|
3732
|
+
try {
|
|
3733
|
+
record = on_record.call(null, record, info);
|
|
3734
|
+
} catch (err) {
|
|
3735
|
+
return err;
|
|
3736
|
+
}
|
|
3737
|
+
if (record === undefined || record === null) {
|
|
3738
|
+
return;
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
this.info.bytes_records += this.info.bytes;
|
|
3742
|
+
push(record);
|
|
3743
|
+
},
|
|
3744
|
+
// Return a tuple with the error and the casted value
|
|
3745
|
+
__cast: function (field) {
|
|
3746
|
+
const { columns, relax_column_count } = this.options;
|
|
3747
|
+
const isColumns = Array.isArray(columns);
|
|
3748
|
+
// Dont loose time calling cast
|
|
3749
|
+
// because the final record is an object
|
|
3750
|
+
// and this field can't be associated to a key present in columns
|
|
3751
|
+
if (
|
|
3752
|
+
isColumns === true &&
|
|
3753
|
+
relax_column_count &&
|
|
3754
|
+
this.options.columns.length <= this.state.record.length
|
|
3755
|
+
) {
|
|
3756
|
+
return [undefined, undefined];
|
|
3757
|
+
}
|
|
3758
|
+
if (this.state.castField !== null) {
|
|
3759
|
+
try {
|
|
3760
|
+
const info = this.__infoField();
|
|
3761
|
+
return [undefined, this.state.castField.call(null, field, info)];
|
|
3762
|
+
} catch (err) {
|
|
3763
|
+
return [err];
|
|
3764
|
+
}
|
|
3765
|
+
}
|
|
3766
|
+
if (this.__isFloat(field)) {
|
|
3767
|
+
return [undefined, parseFloat(field)];
|
|
3768
|
+
} else if (this.options.cast_date !== false) {
|
|
3769
|
+
const info = this.__infoField();
|
|
3770
|
+
return [undefined, this.options.cast_date.call(null, field, info)];
|
|
3771
|
+
}
|
|
3772
|
+
return [undefined, field];
|
|
3773
|
+
},
|
|
3774
|
+
__compareBytes: function (sourceBuf, targetBuf, targetPos, firstByte) {
|
|
3775
|
+
if (sourceBuf[0] !== firstByte) return 0;
|
|
3776
|
+
const sourceLength = sourceBuf.length;
|
|
3777
|
+
for (let i = 1; i < sourceLength; i++) {
|
|
3778
|
+
if (sourceBuf[i] !== targetBuf[targetPos + i]) return 0;
|
|
3779
|
+
}
|
|
3780
|
+
return sourceLength;
|
|
3781
|
+
},
|
|
3782
|
+
// Helper to test if a character is trimable
|
|
3783
|
+
__isCharTrimable: function (buf, pos) {
|
|
3784
|
+
const { timchars, timcharFirstBytes } = this.state;
|
|
3785
|
+
// Fast bail-out: non-whitespace bytes (the common case) are rejected
|
|
3786
|
+
// without scanning the full timchar list.
|
|
3787
|
+
const first = buf[pos];
|
|
3788
|
+
if (first === undefined || timcharFirstBytes[first] === 0) return 0;
|
|
3789
|
+
loop1: for (let i = 0; i < timchars.length; i++) {
|
|
3790
|
+
const timchar = timchars[i];
|
|
3791
|
+
for (let j = 0; j < timchar.length; j++) {
|
|
3792
|
+
if (timchar[j] !== buf[pos + j]) continue loop1;
|
|
3793
|
+
}
|
|
3794
|
+
return timchar.length;
|
|
3795
|
+
}
|
|
3796
|
+
return 0;
|
|
3797
|
+
},
|
|
3798
|
+
__isDelimiter: function (buf, pos, chr) {
|
|
3799
|
+
const { delimiter, ignore_last_delimiters } = this.options;
|
|
3800
|
+
if (
|
|
3801
|
+
ignore_last_delimiters === true &&
|
|
3802
|
+
this.state.record.length === this.options.columns.length - 1
|
|
3803
|
+
) {
|
|
3804
|
+
return 0;
|
|
3805
|
+
} else if (
|
|
3806
|
+
ignore_last_delimiters !== false &&
|
|
3807
|
+
typeof ignore_last_delimiters === "number" &&
|
|
3808
|
+
this.state.record.length === ignore_last_delimiters - 1
|
|
3809
|
+
) {
|
|
3810
|
+
return 0;
|
|
3811
|
+
}
|
|
3812
|
+
loop1: for (let i = 0; i < delimiter.length; i++) {
|
|
3813
|
+
const del = delimiter[i];
|
|
3814
|
+
if (del[0] === chr) {
|
|
3815
|
+
for (let j = 1; j < del.length; j++) {
|
|
3816
|
+
if (del[j] !== buf[pos + j]) continue loop1;
|
|
3817
|
+
}
|
|
3818
|
+
return del.length;
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
return 0;
|
|
3822
|
+
},
|
|
3823
|
+
__isEscape: function (buf, pos, chr) {
|
|
3824
|
+
const { escape } = this.options;
|
|
3825
|
+
if (escape === null) return false;
|
|
3826
|
+
const l = escape.length;
|
|
3827
|
+
if (escape[0] === chr) {
|
|
3828
|
+
for (let i = 0; i < l; i++) {
|
|
3829
|
+
if (escape[i] !== buf[pos + i]) {
|
|
3830
|
+
return false;
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
return true;
|
|
3834
|
+
}
|
|
3835
|
+
return false;
|
|
3836
|
+
},
|
|
3837
|
+
__isFloat: function (value) {
|
|
3838
|
+
return value - parseFloat(value) + 1 >= 0; // Borrowed from jquery
|
|
3839
|
+
},
|
|
3840
|
+
// Keep it in case we implement the `cast_int` option
|
|
3841
|
+
// __isInt(value){
|
|
3842
|
+
// // return Number.isInteger(parseInt(value))
|
|
3843
|
+
// // return !isNaN( parseInt( obj ) );
|
|
3844
|
+
// return /^(\-|\+)?[1-9][0-9]*$/.test(value)
|
|
3845
|
+
// }
|
|
3846
|
+
__isQuote: function (buf, pos) {
|
|
3847
|
+
const { quote } = this.options;
|
|
3848
|
+
if (quote === null) return false;
|
|
3849
|
+
const l = quote.length;
|
|
3850
|
+
for (let i = 0; i < l; i++) {
|
|
3851
|
+
if (quote[i] !== buf[pos + i]) {
|
|
3852
|
+
return false;
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
return true;
|
|
3856
|
+
},
|
|
3857
|
+
__isRecordDelimiter: function (chr, buf, pos) {
|
|
3858
|
+
const { record_delimiter } = this.options;
|
|
3859
|
+
const recordDelimiterLength = record_delimiter.length;
|
|
3860
|
+
loop1: for (let i = 0; i < recordDelimiterLength; i++) {
|
|
3861
|
+
const rd = record_delimiter[i];
|
|
3862
|
+
const rdLength = rd.length;
|
|
3863
|
+
if (rd[0] !== chr) {
|
|
3864
|
+
continue;
|
|
3865
|
+
}
|
|
3866
|
+
for (let j = 1; j < rdLength; j++) {
|
|
3867
|
+
if (rd[j] !== buf[pos + j]) {
|
|
3868
|
+
continue loop1;
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
return rd.length;
|
|
3872
|
+
}
|
|
3873
|
+
return 0;
|
|
3874
|
+
},
|
|
3875
|
+
__autoDiscoverRecordDelimiter: function (buf, pos) {
|
|
3876
|
+
const { encoding } = this.options;
|
|
3877
|
+
// Note, we don't need to cache this information in state,
|
|
3878
|
+
// It is only called on the first line until we find out a suitable
|
|
3879
|
+
// record delimiter.
|
|
3880
|
+
const rds = [
|
|
3881
|
+
// Important, the windows line ending must be before mac os 9
|
|
3882
|
+
Buffer.from("\r\n", encoding),
|
|
3883
|
+
Buffer.from("\n", encoding),
|
|
3884
|
+
Buffer.from("\r", encoding),
|
|
3885
|
+
];
|
|
3886
|
+
loop: for (let i = 0; i < rds.length; i++) {
|
|
3887
|
+
const l = rds[i].length;
|
|
3888
|
+
for (let j = 0; j < l; j++) {
|
|
3889
|
+
if (rds[i][j] !== buf[pos + j]) {
|
|
3890
|
+
continue loop;
|
|
3891
|
+
}
|
|
3892
|
+
}
|
|
3893
|
+
this.options.record_delimiter.push(rds[i]);
|
|
3894
|
+
this.state.recordDelimiterMaxLength = rds[i].length;
|
|
3895
|
+
return rds[i].length;
|
|
3896
|
+
}
|
|
3897
|
+
return 0;
|
|
3898
|
+
},
|
|
3899
|
+
__error: function (msg) {
|
|
3900
|
+
const { encoding, raw, skip_records_with_error } = this.options;
|
|
3901
|
+
const err = typeof msg === "string" ? new Error(msg) : msg;
|
|
3902
|
+
if (skip_records_with_error) {
|
|
3903
|
+
this.state.recordHasError = true;
|
|
3904
|
+
if (this.options.on_skip !== undefined) {
|
|
3905
|
+
try {
|
|
3906
|
+
this.options.on_skip(
|
|
3907
|
+
err,
|
|
3908
|
+
raw ? this.state.rawBuffer.toString(encoding) : undefined,
|
|
3909
|
+
);
|
|
3910
|
+
} catch (err) {
|
|
3911
|
+
return err;
|
|
3912
|
+
}
|
|
3913
|
+
}
|
|
3914
|
+
// this.emit('skip', err, raw ? this.state.rawBuffer.toString(encoding) : undefined);
|
|
3915
|
+
return undefined;
|
|
3916
|
+
} else {
|
|
3917
|
+
return err;
|
|
3918
|
+
}
|
|
3919
|
+
},
|
|
3920
|
+
__infoDataSet: function () {
|
|
3921
|
+
return {
|
|
3922
|
+
...this.info,
|
|
3923
|
+
columns: this.options.columns,
|
|
3924
|
+
};
|
|
3925
|
+
},
|
|
3926
|
+
__infoRecord: function () {
|
|
3927
|
+
const { columns, raw, encoding } = this.options;
|
|
3928
|
+
return {
|
|
3929
|
+
...this.__infoDataSet(),
|
|
3930
|
+
bytes_records: this.info.bytes,
|
|
3931
|
+
error: this.state.error,
|
|
3932
|
+
header: columns === true,
|
|
3933
|
+
index: this.state.record.length,
|
|
3934
|
+
raw: raw ? this.state.rawBuffer.toString(encoding) : undefined,
|
|
3935
|
+
};
|
|
3936
|
+
},
|
|
3937
|
+
__infoField: function () {
|
|
3938
|
+
const { columns } = this.options;
|
|
3939
|
+
const isColumns = Array.isArray(columns);
|
|
3940
|
+
// Bytes records are only incremented when all records'fields are parsed
|
|
3941
|
+
const bytes_records = this.info.bytes_records;
|
|
3942
|
+
return {
|
|
3943
|
+
...this.__infoRecord(),
|
|
3944
|
+
bytes_records: bytes_records,
|
|
3945
|
+
column:
|
|
3946
|
+
isColumns === true
|
|
3947
|
+
? columns.length > this.state.record.length
|
|
3948
|
+
? columns[this.state.record.length].name
|
|
3949
|
+
: null
|
|
3950
|
+
: this.state.record.length,
|
|
3951
|
+
quoting: this.state.wasQuoting,
|
|
3952
|
+
};
|
|
3953
|
+
},
|
|
3954
|
+
};
|
|
3955
|
+
};
|
|
3956
|
+
|
|
3957
|
+
const parse = function (data, opts = {}) {
|
|
3958
|
+
if (typeof data === "string") {
|
|
3959
|
+
data = Buffer.from(data);
|
|
3960
|
+
}
|
|
3961
|
+
const records = opts && opts.objname ? Object.create(null) : [];
|
|
3962
|
+
const parser = transform(opts);
|
|
3963
|
+
const push = (record) => {
|
|
3964
|
+
if (parser.options.objname === undefined) records.push(record);
|
|
3965
|
+
else {
|
|
3966
|
+
records[record[0]] = record[1];
|
|
3967
|
+
}
|
|
3968
|
+
};
|
|
3969
|
+
const close = () => {};
|
|
3970
|
+
const error = parser.parse(data, true, push, close);
|
|
3971
|
+
if (error !== undefined) throw error;
|
|
3972
|
+
return records;
|
|
3973
|
+
};
|
|
3974
|
+
|
|
3975
|
+
exports.CsvError = CsvError;
|
|
3976
|
+
exports.normalize_options = normalize_options;
|
|
3977
|
+
exports.parse = parse;
|
|
3978
|
+
//# sourceMappingURL=sync.js.map
|