New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@internetarchive/field-parsers

Package Overview
Dependencies
Maintainers
15
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@internetarchive/field-parsers - npm Package Compare versions

Comparing version 0.1.2-alpha.2 to 0.1.2

5

dist/src/field-types/list.d.ts
import { FieldParserInterface, FieldParserRawValue } from '../field-parser-interface';
export declare class ListParser<T> implements FieldParserInterface<T[]> {
private parser;
constructor(parser: FieldParserInterface<T>);
private separators;
constructor(parser: FieldParserInterface<T>, options?: {
separators?: string[];
});
/** @inheritdoc */

@@ -6,0 +9,0 @@ parseValue(rawValue: FieldParserRawValue): T[];

15

dist/src/field-types/list.js
export class ListParser {
constructor(parser) {
constructor(parser, options) {
this.separators = [',', ';'];
this.parser = parser;
if (options && options.separators) {
this.separators = options.separators;
}
}

@@ -9,6 +13,7 @@ /** @inheritdoc */

let results = [];
// first try splitting by comma, then by semi-colon
results = stringifiedValue.split(',');
if (results.length === 1)
results = stringifiedValue.split(';');
for (const separator of this.separators) {
results = stringifiedValue.split(separator);
if (results.length > 1)
break;
}
return this.parseListValues(results);

@@ -15,0 +20,0 @@ }

@@ -55,3 +55,15 @@ import { expect } from '@open-wc/testing';

});
it('can parse a list of strings with custom separator', async () => {
const stringParser = new StringParser();
const parser = new ListParser(stringParser, { separators: ['-'] });
const response = parser.parseValue('boop - bop - beep');
expect(response).to.deep.equal(['boop', 'bop', 'beep']);
});
it('can parse a list of strings with the second custom separator', async () => {
const stringParser = new StringParser();
const parser = new ListParser(stringParser, { separators: ['-', '|'] });
const response = parser.parseValue('boop | bop | beep');
expect(response).to.deep.equal(['boop', 'bop', 'beep']);
});
});
//# sourceMappingURL=list.test.js.map
{
"version": "0.1.2-alpha.2",
"version": "0.1.2",
"name": "@internetarchive/field-parsers",

@@ -4,0 +4,0 @@ "description": "Field parsers for Internet Archive metadata fields.",

@@ -9,4 +9,14 @@ import {

constructor(parser: FieldParserInterface<T>) {
private separators = [',', ';'];
constructor(
parser: FieldParserInterface<T>,
options?: {
separators?: string[];
}
) {
this.parser = parser;
if (options && options.separators) {
this.separators = options.separators;
}
}

@@ -18,5 +28,8 @@

let results: string[] = [];
// first try splitting by comma, then by semi-colon
results = stringifiedValue.split(',');
if (results.length === 1) results = stringifiedValue.split(';');
for (const separator of this.separators) {
results = stringifiedValue.split(separator);
if (results.length > 1) break;
}
return this.parseListValues(results);

@@ -23,0 +36,0 @@ }

@@ -63,2 +63,16 @@ import { expect } from '@open-wc/testing';

});
it('can parse a list of strings with custom separator', async () => {
const stringParser = new StringParser();
const parser = new ListParser(stringParser, { separators: ['-'] });
const response = parser.parseValue('boop - bop - beep');
expect(response).to.deep.equal(['boop', 'bop', 'beep']);
});
it('can parse a list of strings with the second custom separator', async () => {
const stringParser = new StringParser();
const parser = new ListParser(stringParser, { separators: ['-', '|'] });
const response = parser.parseValue('boop | bop | beep');
expect(response).to.deep.equal(['boop', 'bop', 'beep']);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc