Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lexure

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lexure - npm Package Compare versions

Comparing version 0.14.1 to 0.15.0

4

dist/lib/lexer.js

@@ -16,2 +16,3 @@ "use strict";

this.input = input;
this.pWs();
}

@@ -72,5 +73,2 @@ /**

nextToken() {
if (this.position === 0) {
this.pWs();
}
return this.pQuoted() || this.pWord();

@@ -77,0 +75,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.none = exports.some = void 0;
exports.orOption = exports.maybeOption = exports.none = exports.some = void 0;
/**

@@ -22,2 +22,39 @@ * Creates a Some.

exports.none = none;
/**
* Creates an Option from a value that could be null or undefined.
*
* ```ts
* console.log(maybeOption(1));
* >>> { exists: true, value: 1 }
*
* console.log(maybeOption(null));
* >>> { exists: false }
*
* console.log(maybeOption(undefined));
* >>> { exists: false }
* ```
* @param x - A nullable value.
* @returns An Option.
*/
function maybeOption(x) {
if (x == null) {
return none();
}
return some(x);
}
exports.maybeOption = maybeOption;
/**
* Gets the first Some from many Options.
* @param xs - The Options.
* @return The first Some, or None if there were no Some.
*/
function orOption(...xs) {
for (const x of xs) {
if (x.exists) {
return x;
}
}
return none();
}
exports.orOption = orOption;
//# sourceMappingURL=option.js.map

@@ -45,8 +45,11 @@ "use strict";

* Gets the next parsed tokens.
* If a parser output is passed in, that output will be mutated, otherwise a new one is made.
* @param output - Parser output to mutate.
* @returns An iterator result containing parser output.
*/
next() {
next(output) {
if (this.finished) {
return { done: true, value: null };
}
const ts = this.processToken();
const ts = this.processToken(output);
if (ts == null) {

@@ -57,6 +60,9 @@ throw new Error('Unexpected end of input (this should never happen).');

}
processToken() {
return this.pFlag() || this.pOption() || this.pCompactOption() || this.pOrdered();
processToken(output) {
return this.pFlag(output)
|| this.pOption(output)
|| this.pCompactOption(output)
|| this.pOrdered(output);
}
pFlag() {
pFlag(output = parserOutput_1.emptyOutput()) {
const t = this.input[this.position];

@@ -68,7 +74,6 @@ const f = this.unorderedStrategy.matchFlag(t.value);

this.shift(1);
const output = parserOutput_1.emptyOutput();
output.flags.add(f);
return output;
}
pOption() {
pOption(output = parserOutput_1.emptyOutput()) {
const t = this.input[this.position];

@@ -80,4 +85,5 @@ const o = this.unorderedStrategy.matchOption(t.value);

this.shift(1);
const output = parserOutput_1.emptyOutput();
output.options.set(o, []);
if (!output.options.has(o)) {
output.options.set(o, []);
}
const n = this.input[this.position];

@@ -98,3 +104,3 @@ if (n == null) {

}
pCompactOption() {
pCompactOption(output = parserOutput_1.emptyOutput()) {
const t = this.input[this.position];

@@ -106,10 +112,14 @@ const o = this.unorderedStrategy.matchCompactOption(t.value);

this.shift(1);
const output = parserOutput_1.emptyOutput();
output.options.set(o[0], [o[1]]);
if (!output.options.has(o[0])) {
output.options.set(o[0], [o[1]]);
}
else {
const a = output.options.get(o[0]);
a.push(o[1]);
}
return output;
}
pOrdered() {
pOrdered(output = parserOutput_1.emptyOutput()) {
const t = this.input[this.position];
this.shift(1);
const output = parserOutput_1.emptyOutput();
output.ordered.push(t);

@@ -134,3 +144,8 @@ return output;

parse() {
return parserOutput_1.mergeOutputs(...this);
const output = parserOutput_1.emptyOutput();
let r = this.next(output);
while (!r.done) {
r = this.next(output);
}
return output;
}

@@ -137,0 +152,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.err_ = exports.err = exports.ok = void 0;
exports.orResultLast = exports.orResultFirst = exports.orResultAll = exports.maybeResult = exports.err_ = exports.err = exports.ok = void 0;
/**

@@ -32,2 +32,85 @@ * Creates an Ok.

exports.err_ = err_;
/**
* Creates a Result from a value that could be null or undefined.
*
* ```ts
* console.log(maybeResult(1, 'bad'));
* >>> { success: true, value: 1 }
*
* console.log(maybeResult(null, 'bad'));
* >>> { success: false, error: 'bad' }
*
* console.log(maybeResult(undefined, 'bad'));
* >>> { success: false, error: 'bad' }
* ```
* @param x - A nullable value.
* @param e - The error to use.
* @returns A Result.
*/
function maybeResult(x, e) {
if (x == null) {
return err(e);
}
return ok(x);
}
exports.maybeResult = maybeResult;
/**
* Gets the first Ok from many Results.
* @param x - The first Result.
* @param xs - The remaining Results; this encoding is to ensure there is at least one Result.
* @return The first Ok, or all the Errs if there were no Ok.
*/
function orResultAll(x, ...xs) {
if (x.success) {
return x;
}
const es = [x.error];
for (const x of xs) {
if (x.success) {
return x;
}
es.push(x.error);
}
return err(es);
}
exports.orResultAll = orResultAll;
/**
* Gets the first Ok from many Results.
* @param x - The first Result.
* @param xs - The remaining Results; this encoding is to ensure there is at least one Result.
* @return The first Ok, or the first Err if there were no Ok.
*/
function orResultFirst(x, ...xs) {
if (x.success) {
return x;
}
const e = x.error;
for (const x of xs) {
if (x.success) {
return x;
}
}
return err(e);
}
exports.orResultFirst = orResultFirst;
/**
* Gets the first Ok from many Results.
* @param x - The first Result.
* @param xs - The remaining Results; this encoding is to ensure there is at least one Result.
* @return The first Ok, or the last Err if there were no Ok.
*/
function orResultLast(x, ...xs) {
if (x.success) {
return x;
}
let e = x.error;
for (const x of xs) {
if (x.success) {
return x;
}
e = x.error;
}
return err(e);
}
exports.orResultLast = orResultLast;
//# sourceMappingURL=result.js.map

@@ -42,1 +42,24 @@ /**

export declare function none(): None;
/**
* Creates an Option from a value that could be null or undefined.
*
* ```ts
* console.log(maybeOption(1));
* >>> { exists: true, value: 1 }
*
* console.log(maybeOption(null));
* >>> { exists: false }
*
* console.log(maybeOption(undefined));
* >>> { exists: false }
* ```
* @param x - A nullable value.
* @returns An Option.
*/
export declare function maybeOption<T>(x: T | null | undefined): Option<T>;
/**
* Gets the first Some from many Options.
* @param xs - The Options.
* @return The first Some, or None if there were no Some.
*/
export declare function orOption<T>(...xs: Option<T>[]): Option<T>;

@@ -7,3 +7,3 @@ import { UnorderedStrategy } from './unordered';

*/
export declare class Parser implements IterableIterator<ParserOutput> {
export declare class Parser implements IterableIterator<ParserOutput>, Iterator<ParserOutput, null, ParserOutput | undefined> {
private readonly input;

@@ -36,4 +36,7 @@ private unorderedStrategy;

* Gets the next parsed tokens.
* If a parser output is passed in, that output will be mutated, otherwise a new one is made.
* @param output - Parser output to mutate.
* @returns An iterator result containing parser output.
*/
next(): IteratorResult<ParserOutput>;
next(output?: ParserOutput): IteratorResult<ParserOutput>;
private processToken;

@@ -40,0 +43,0 @@ private pFlag;

@@ -54,1 +54,40 @@ /**

export declare function err_(): Err<null>;
/**
* Creates a Result from a value that could be null or undefined.
*
* ```ts
* console.log(maybeResult(1, 'bad'));
* >>> { success: true, value: 1 }
*
* console.log(maybeResult(null, 'bad'));
* >>> { success: false, error: 'bad' }
*
* console.log(maybeResult(undefined, 'bad'));
* >>> { success: false, error: 'bad' }
* ```
* @param x - A nullable value.
* @param e - The error to use.
* @returns A Result.
*/
export declare function maybeResult<T, E>(x: T | null | undefined, e: E): Result<T, E>;
/**
* Gets the first Ok from many Results.
* @param x - The first Result.
* @param xs - The remaining Results; this encoding is to ensure there is at least one Result.
* @return The first Ok, or all the Errs if there were no Ok.
*/
export declare function orResultAll<T, E>(x: Result<T, E>, ...xs: Result<T, E>[]): Result<T, E[]>;
/**
* Gets the first Ok from many Results.
* @param x - The first Result.
* @param xs - The remaining Results; this encoding is to ensure there is at least one Result.
* @return The first Ok, or the first Err if there were no Ok.
*/
export declare function orResultFirst<T, E>(x: Result<T, E>, ...xs: Result<T, E>[]): Result<T, E>;
/**
* Gets the first Ok from many Results.
* @param x - The first Result.
* @param xs - The remaining Results; this encoding is to ensure there is at least one Result.
* @return The first Ok, or the last Err if there were no Ok.
*/
export declare function orResultLast<T, E>(x: Result<T, E>, ...xs: Result<T, E>[]): Result<T, E>;
{
"name": "lexure",
"version": "0.14.1",
"version": "0.15.0",
"description": "Parser and utilities for non-technical user input.",

@@ -36,2 +36,3 @@ "keywords": [

"lint": "eslint ./src ./test --ext .ts",
"bench": "npm run build && node benchmarks",
"build": "rimraf dist && tsc -p tsconfig.build.json",

@@ -67,2 +68,3 @@ "docs": "rimraf docs/reference && typedoc",

"devDependencies": {
"@types/benchmark": "^1.0.33",
"@types/jest": "^26.0.0",

@@ -72,2 +74,3 @@ "@types/node": "^14.0.13",

"@typescript-eslint/parser": "^3.2.0",
"benchmark": "^2.1.4",
"eslint": "^7.2.0",

@@ -74,0 +77,0 @@ "eslint-plugin-jest": "^23.13.2",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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