gff-nostream
Advanced tools
Comparing version 1.3.1 to 1.3.3
@@ -1,2 +0,2 @@ | ||
import { GFF3Item } from './util'; | ||
import { GFF3Feature } from './util'; | ||
/** Parser options */ | ||
@@ -22,3 +22,11 @@ export interface ParseOptions { | ||
} | ||
export declare function parseStringSync(str: string, inputOptions?: ParseOptions): GFF3Item[]; | ||
/** | ||
* Synchronously parse a string containing GFF3 and return an array of the | ||
* parsed items. | ||
* | ||
* @param str - GFF3 string | ||
* @param inputOptions - Parsing options | ||
* @returns array of parsed features, directives, comments and/or sequences | ||
*/ | ||
export declare function parseStringSync(str: string): GFF3Feature[]; | ||
export { type GFF3FeatureLine, type GFF3Comment, type GFF3FeatureLineWithRefs, type GFF3Directive, type GFF3Sequence, type GFF3Feature, type GFF3Item, } from './util'; |
@@ -8,26 +8,15 @@ "use strict"; | ||
const parse_1 = __importDefault(require("./parse")); | ||
// shared arg processing for the parse routines | ||
function _processParseOptions(options) { | ||
const out = Object.assign({ encoding: 'utf8', parseFeatures: true, parseDirectives: false, parseSequences: true, parseComments: false, disableDerivesFromReferences: false }, options); | ||
if (options.parseAll) { | ||
out.parseFeatures = true; | ||
out.parseDirectives = true; | ||
out.parseComments = true; | ||
out.parseSequences = true; | ||
} | ||
return out; | ||
} | ||
function parseStringSync(str, inputOptions = {}) { | ||
if (!str) { | ||
return []; | ||
} | ||
const options = _processParseOptions(inputOptions); | ||
/** | ||
* Synchronously parse a string containing GFF3 and return an array of the | ||
* parsed items. | ||
* | ||
* @param str - GFF3 string | ||
* @param inputOptions - Parsing options | ||
* @returns array of parsed features, directives, comments and/or sequences | ||
*/ | ||
function parseStringSync(str) { | ||
const items = []; | ||
const push = items.push.bind(items); | ||
const parser = new parse_1.default({ | ||
featureCallback: options.parseFeatures ? push : undefined, | ||
directiveCallback: options.parseDirectives ? push : undefined, | ||
commentCallback: options.parseComments ? push : undefined, | ||
sequenceCallback: options.parseSequences ? push : undefined, | ||
disableDerivesFromReferences: options.disableDerivesFromReferences || false, | ||
featureCallback: arg => items.push(arg), | ||
disableDerivesFromReferences: true, | ||
errorCallback: err => { | ||
@@ -37,3 +26,5 @@ throw err; | ||
}); | ||
str.split(/\r?\n/).forEach(parser.addLine.bind(parser)); | ||
for (const line of str.split(/\r?\n/)) { | ||
parser.addLine(line); | ||
} | ||
parser.finish(); | ||
@@ -40,0 +31,0 @@ return items; |
@@ -1,2 +0,2 @@ | ||
import { GFF3Item } from './util'; | ||
import { GFF3Feature } from './util'; | ||
/** Parser options */ | ||
@@ -22,3 +22,11 @@ export interface ParseOptions { | ||
} | ||
export declare function parseStringSync(str: string, inputOptions?: ParseOptions): GFF3Item[]; | ||
/** | ||
* Synchronously parse a string containing GFF3 and return an array of the | ||
* parsed items. | ||
* | ||
* @param str - GFF3 string | ||
* @param inputOptions - Parsing options | ||
* @returns array of parsed features, directives, comments and/or sequences | ||
*/ | ||
export declare function parseStringSync(str: string): GFF3Feature[]; | ||
export { type GFF3FeatureLine, type GFF3Comment, type GFF3FeatureLineWithRefs, type GFF3Directive, type GFF3Sequence, type GFF3Feature, type GFF3Item, } from './util'; |
import Parser from './parse'; | ||
// shared arg processing for the parse routines | ||
function _processParseOptions(options) { | ||
const out = { | ||
encoding: 'utf8', | ||
parseFeatures: true, | ||
parseDirectives: false, | ||
parseSequences: true, | ||
parseComments: false, | ||
disableDerivesFromReferences: false, | ||
...options, | ||
}; | ||
if (options.parseAll) { | ||
out.parseFeatures = true; | ||
out.parseDirectives = true; | ||
out.parseComments = true; | ||
out.parseSequences = true; | ||
} | ||
return out; | ||
} | ||
export function parseStringSync(str, inputOptions = {}) { | ||
if (!str) { | ||
return []; | ||
} | ||
const options = _processParseOptions(inputOptions); | ||
/** | ||
* Synchronously parse a string containing GFF3 and return an array of the | ||
* parsed items. | ||
* | ||
* @param str - GFF3 string | ||
* @param inputOptions - Parsing options | ||
* @returns array of parsed features, directives, comments and/or sequences | ||
*/ | ||
export function parseStringSync(str) { | ||
const items = []; | ||
const push = items.push.bind(items); | ||
const parser = new Parser({ | ||
featureCallback: options.parseFeatures ? push : undefined, | ||
directiveCallback: options.parseDirectives ? push : undefined, | ||
commentCallback: options.parseComments ? push : undefined, | ||
sequenceCallback: options.parseSequences ? push : undefined, | ||
disableDerivesFromReferences: options.disableDerivesFromReferences || false, | ||
featureCallback: arg => items.push(arg), | ||
disableDerivesFromReferences: true, | ||
errorCallback: err => { | ||
@@ -38,3 +19,5 @@ throw err; | ||
}); | ||
str.split(/\r?\n/).forEach(parser.addLine.bind(parser)); | ||
for (const line of str.split(/\r?\n/)) { | ||
parser.addLine(line); | ||
} | ||
parser.finish(); | ||
@@ -41,0 +24,0 @@ return items; |
{ | ||
"name": "gff-nostream", | ||
"version": "1.3.1", | ||
"version": "1.3.3", | ||
"description": "utilities to read GFF3 data", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
import Parser from './parse' | ||
import { GFF3Item } from './util' | ||
import { | ||
GFF3Comment, | ||
GFF3Directive, | ||
GFF3Feature, | ||
GFF3Item, | ||
GFF3Sequence, | ||
parseFeature, | ||
} from './util' | ||
@@ -27,42 +34,15 @@ /** Parser options */ | ||
// shared arg processing for the parse routines | ||
function _processParseOptions(options: ParseOptions): ParseOptionsProcessed { | ||
const out = { | ||
encoding: 'utf8' as const, | ||
parseFeatures: true, | ||
parseDirectives: false, | ||
parseSequences: true, | ||
parseComments: false, | ||
disableDerivesFromReferences: false, | ||
...options, | ||
} | ||
if (options.parseAll) { | ||
out.parseFeatures = true | ||
out.parseDirectives = true | ||
out.parseComments = true | ||
out.parseSequences = true | ||
} | ||
return out | ||
} | ||
export function parseStringSync( | ||
str: string, | ||
inputOptions: ParseOptions = {}, | ||
): GFF3Item[] { | ||
if (!str) { | ||
return [] | ||
} | ||
const options = _processParseOptions(inputOptions) | ||
const items: GFF3Item[] = [] | ||
const push = items.push.bind(items) | ||
/** | ||
* Synchronously parse a string containing GFF3 and return an array of the | ||
* parsed items. | ||
* | ||
* @param str - GFF3 string | ||
* @param inputOptions - Parsing options | ||
* @returns array of parsed features, directives, comments and/or sequences | ||
*/ | ||
export function parseStringSync(str: string): GFF3Feature[] { | ||
const items: GFF3Feature[] = [] | ||
const parser = new Parser({ | ||
featureCallback: options.parseFeatures ? push : undefined, | ||
directiveCallback: options.parseDirectives ? push : undefined, | ||
commentCallback: options.parseComments ? push : undefined, | ||
sequenceCallback: options.parseSequences ? push : undefined, | ||
disableDerivesFromReferences: options.disableDerivesFromReferences || false, | ||
featureCallback: arg => items.push(arg), | ||
disableDerivesFromReferences: true, | ||
errorCallback: err => { | ||
@@ -73,3 +53,5 @@ throw err | ||
str.split(/\r?\n/).forEach(parser.addLine.bind(parser)) | ||
for (const line of str.split(/\r?\n/)) { | ||
parser.addLine(line) | ||
} | ||
parser.finish() | ||
@@ -76,0 +58,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
133996
2588