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

@bodar/totallylazy

Package Overview
Dependencies
Maintainers
2
Versions
310
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bodar/totallylazy - npm Package Compare versions

Comparing version 0.467.309 to 0.493.336

array.d.ts

1

arrays.d.ts
export declare function flatten<T>(values: T[][]): T[];
export declare function unique<T>(a: T[]): T[];
//# sourceMappingURL=arrays.d.ts.map

@@ -5,3 +5,3 @@ "use strict";

function flatten(values) {
return values.reduce((a, ms) => a.concat(ms), []);
return values.flatMap(v => v);
}

@@ -8,0 +8,0 @@ exports.flatten = flatten;

@@ -30,2 +30,1 @@ import { Comparator } from "./collections";

}
//# sourceMappingURL=avltree.d.ts.map

@@ -19,3 +19,3 @@ "use strict";

static of(entries, comparator = collections_1.ascending) {
return AVLTree.preSorted(entries.sort(collections_1.by(0)), comparator, AVLTree.empty(comparator));
return AVLTree.preSorted(entries.sort((0, collections_1.by)(0)), comparator, AVLTree.empty(comparator));
}

@@ -209,6 +209,6 @@ static preSorted(entries, comparator, empty) {

}
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy
], Node.prototype, "balance", null);
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy

@@ -215,0 +215,0 @@ ], Node.prototype, "height", null);

export declare function cache(target: any, name: string, descriptor: PropertyDescriptor): any;
export declare function caching<F extends Function>(fun: F): F;
//# sourceMappingURL=cache.d.ts.map

@@ -32,2 +32,1 @@ export declare type Names = string[];

export declare function splitByRegex(value: string): string[];
//# sourceMappingURL=characters.d.ts.map

@@ -1,5 +0,4 @@

import { Transducer } from "./transducers";
export declare type Mapper<A, B> = (a: A) => B;
export declare type Comparator<A> = (a: A, b: A) => number;
export declare function ascending<T>(a: T, b: T): 1 | 0 | -1;
export declare function ascending<T>(a: T, b: T): 1 | -1 | 0;
export declare function descending<T>(a: T, b: T): number;

@@ -21,29 +20,5 @@ export declare function comparators<T>(...comparators: Comparator<T>[]): Comparator<T>;

export declare type IterableLike<T> = Iterable<T> | ArrayLike<T>;
export declare function array<A>(iterable: IterableLike<A>): Array<A>;
export declare function array<A, B>(a: IterableLike<A>, b: Transducer<A, B>): Array<B>;
export declare function array<A, B, C>(a: IterableLike<A>, b: Transducer<A, B>, c: Transducer<B, C>): Array<C>;
export declare function array<A, B, C, D>(a: IterableLike<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>): Array<D>;
export declare function array<A, B, C, D, E>(a: IterableLike<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>, e: Transducer<D, E>): Array<E>;
export declare function array<A, B, C, D, E, F>(a: IterableLike<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>, e: Transducer<D, E>, f: Transducer<E, F>): Array<F>;
export declare function array<A>(iterable: AsyncIterable<A>): Promise<Array<A>>;
export declare function array<A, B>(a: AsyncIterable<A>, b: Transducer<A, B>): Promise<Array<B>>;
export declare function array<A, B, C>(a: AsyncIterable<A>, b: Transducer<A, B>, c: Transducer<B, C>): Promise<Array<C>>;
export declare function array<A, B, C, D>(a: AsyncIterable<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>): Promise<Array<D>>;
export declare function array<A, B, C, D, E>(a: AsyncIterable<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>, e: Transducer<D, E>): Promise<Array<E>>;
export declare function array<A, B, C, D, E, F>(a: AsyncIterable<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>, e: Transducer<D, E>, f: Transducer<E, F>): Promise<Array<F>>;
export declare function toAsyncIterable<A>(promise: PromiseLike<A>): AsyncIterable<A>;
export declare function by<A, K extends keyof A>(key: K, comparator?: Comparator<A[K]>): Comparator<A>;
export declare function by<A, K>(mapper: Mapper<A, K>, comparator?: Comparator<K>): Comparator<A>;
export declare function single<A>(iterable: Iterable<A>): A;
export declare function single<A, B>(a: Iterable<A>, b: Transducer<A, B>): B;
export declare function single<A, B, C>(a: Iterable<A>, b: Transducer<A, B>, c: Transducer<B, C>): C;
export declare function single<A, B, C, D>(a: Iterable<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>): D;
export declare function single<A, B, C, D, E>(a: Iterable<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>, e: Transducer<D, E>): E;
export declare function single<A, B, C, D, E, F>(a: Iterable<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>, e: Transducer<D, E>, f: Transducer<E, F>): F;
export declare function single<A>(iterable: AsyncIterable<A>): Promise<A>;
export declare function single<A, B>(a: AsyncIterable<A>, b: Transducer<A, B>): Promise<B>;
export declare function single<A, B, C>(a: AsyncIterable<A>, b: Transducer<A, B>, c: Transducer<B, C>): Promise<C>;
export declare function single<A, B, C, D>(a: AsyncIterable<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>): Promise<D>;
export declare function single<A, B, C, D, E>(a: AsyncIterable<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>, e: Transducer<D, E>): Promise<E>;
export declare function single<A, B, C, D, E, F>(a: AsyncIterable<A>, b: Transducer<A, B>, c: Transducer<B, C>, d: Transducer<C, D>, e: Transducer<D, E>, f: Transducer<E, F>): Promise<F>;
export declare class AsyncIteratorHandler<T> implements AsyncIterableIterator<T> {

@@ -61,2 +36,1 @@ private handlers;

}
//# sourceMappingURL=collections.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncIteratorHandler = exports.single = exports.by = exports.toAsyncIterable = exports.array = exports.isArrayLike = exports.asyncIterable = exports.iterable = exports.toIterable = exports.isPromiseLike = exports.isAsyncIterable = exports.isIterable = exports.value = exports.key = exports.comparators = exports.descending = exports.ascending = void 0;
exports.AsyncIteratorHandler = exports.by = exports.toAsyncIterable = exports.isArrayLike = exports.asyncIterable = exports.iterable = exports.toIterable = exports.isPromiseLike = exports.isAsyncIterable = exports.isIterable = exports.value = exports.key = exports.comparators = exports.descending = exports.ascending = void 0;
const tslib_1 = require("tslib");
const sequence_1 = require("./sequence");
function ascending(a, b) {

@@ -64,5 +63,5 @@ if (a < b)

function asyncIterable(values) {
return tslib_1.__asyncGenerator(this, arguments, function* asyncIterable_1() {
return (0, tslib_1.__asyncGenerator)(this, arguments, function* asyncIterable_1() {
for (const t of values) {
yield yield tslib_1.__await(t);
yield yield (0, tslib_1.__await)(t);
}

@@ -76,41 +75,5 @@ });

exports.isArrayLike = isArrayLike;
function array(source, ...transducers) {
if (isIterable(source) || isArrayLike(source)) {
// @ts-ignore
return toArray(sequence_1.sequence(source, ...transducers));
}
// @ts-ignore
return toPromiseArray(sequence_1.sequence(source, ...transducers));
}
exports.array = array;
function toArray(iterable) {
const result = [];
for (const value of iterable)
result.push(value);
return result;
}
function toPromiseArray(iterable) {
var iterable_1, iterable_1_1;
var e_1, _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = [];
try {
for (iterable_1 = tslib_1.__asyncValues(iterable); iterable_1_1 = yield iterable_1.next(), !iterable_1_1.done;) {
const value = iterable_1_1.value;
result.push(value);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) yield _a.call(iterable_1);
}
finally { if (e_1) throw e_1.error; }
}
return result;
});
}
function toAsyncIterable(promise) {
return tslib_1.__asyncGenerator(this, arguments, function* toAsyncIterable_1() {
yield yield tslib_1.__await(promise);
return (0, tslib_1.__asyncGenerator)(this, arguments, function* toAsyncIterable_1() {
yield yield (0, tslib_1.__await)(promise);
});

@@ -135,36 +98,2 @@ }

}
function single(source, ...transducers) {
if (isIterable(source)) {
// @ts-ignore
return toSingle(sequence_1.sequence(source, ...transducers));
}
// @ts-ignore
return toSinglePromise(sequence_1.sequence(source, ...transducers));
}
exports.single = single;
function toSingle(iterable) {
for (const a of iterable)
return a;
throw new Error("Expected a single value");
}
function toSinglePromise(iterable) {
var iterable_2, iterable_2_1;
var e_2, _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
for (iterable_2 = tslib_1.__asyncValues(iterable); iterable_2_1 = yield iterable_2.next(), !iterable_2_1.done;) {
const value = iterable_2_1.value;
return value;
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (iterable_2_1 && !iterable_2_1.done && (_a = iterable_2.return)) yield _a.call(iterable_2);
}
finally { if (e_2) throw e_2.error; }
}
throw new Error("Expected a single value");
});
}
class AsyncIteratorHandler {

@@ -171,0 +100,0 @@ constructor() {

@@ -41,2 +41,1 @@ /// <reference types="node" />

};
//# sourceMappingURL=files.d.ts.map

@@ -29,5 +29,5 @@ "use strict";

children() {
return tslib_1.__asyncGenerator(this, arguments, function* children_1() {
const names = yield tslib_1.__await(util_1.promisify(fs.readdir)(this.absolutePath));
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(names.map(name => this.child(name)))));
return (0, tslib_1.__asyncGenerator)(this, arguments, function* children_1() {
const names = yield (0, tslib_1.__await)((0, util_1.promisify)(fs.readdir)(this.absolutePath));
yield (0, tslib_1.__await)(yield* (0, tslib_1.__asyncDelegator)((0, tslib_1.__asyncValues)(names.map(name => this.child(name)))));
});

@@ -42,13 +42,13 @@ }

get stats() {
return util_1.promisify(fs.lstat)(this.absolutePath);
return (0, util_1.promisify)(fs.lstat)(this.absolutePath);
}
descendants() {
return tslib_1.__asyncGenerator(this, arguments, function* descendants_1() {
return (0, tslib_1.__asyncGenerator)(this, arguments, function* descendants_1() {
var e_1, _a;
try {
for (var _b = tslib_1.__asyncValues(this.children()), _c; _c = yield tslib_1.__await(_b.next()), !_c.done;) {
for (var _b = (0, tslib_1.__asyncValues)(this.children()), _c; _c = yield (0, tslib_1.__await)(_b.next()), !_c.done;) {
const child = _c.value;
if (yield tslib_1.__await(child.isDirectory))
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(child.descendants())));
yield yield tslib_1.__await(child);
if (yield (0, tslib_1.__await)(child.isDirectory))
yield (0, tslib_1.__await)(yield* (0, tslib_1.__asyncDelegator)((0, tslib_1.__asyncValues)(child.descendants())));
yield yield (0, tslib_1.__await)(child);
}

@@ -59,3 +59,3 @@ }

try {
if (_c && !_c.done && (_a = _b.return)) yield tslib_1.__await(_a.call(_b));
if (_c && !_c.done && (_a = _b.return)) yield (0, tslib_1.__await)(_a.call(_b));
}

@@ -67,13 +67,13 @@ finally { if (e_1) throw e_1.error; }

bytes() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield util_1.promisify(fs.readFile)(this.absolutePath);
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
return yield (0, util_1.promisify)(fs.readFile)(this.absolutePath);
});
}
content(newContent) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
if (newContent) {
(yield util_1.promisify(fs.writeFile)(this.absolutePath, newContent));
(yield (0, util_1.promisify)(fs.writeFile)(this.absolutePath, newContent));
return newContent;
}
return (yield util_1.promisify(fs.readFile)(this.absolutePath, 'utf-8')).toString();
return (yield (0, util_1.promisify)(fs.readFile)(this.absolutePath, 'utf-8')).toString();
});

@@ -85,4 +85,4 @@ }

append(data, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield util_1.promisify(fs.appendFile)(this.absolutePath, data, options);
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
return yield (0, util_1.promisify)(fs.appendFile)(this.absolutePath, data, options);
});

@@ -94,5 +94,5 @@ }

mkdir() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
if (!(yield this.exists))
yield util_1.promisify(fs.mkdir)(this.absolutePath);
yield (0, util_1.promisify)(fs.mkdir)(this.absolutePath);
return this;

@@ -103,3 +103,3 @@ });

var e_2, _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
if (!(yield this.exists))

@@ -109,3 +109,3 @@ return Promise.resolve();

try {
for (var _b = tslib_1.__asyncValues(this.descendants()), _c; _c = yield _b.next(), !_c.done;) {
for (var _b = (0, tslib_1.__asyncValues)(this.descendants()), _c; _c = yield _b.next(), !_c.done;) {
const descendant = _c.value;

@@ -122,5 +122,5 @@ yield descendant.delete();

}
return yield util_1.promisify(fs.rmdir)(this.absolutePath);
return yield (0, util_1.promisify)(fs.rmdir)(this.absolutePath);
}
return yield util_1.promisify(fs.unlink)(this.absolutePath);
return yield (0, util_1.promisify)(fs.unlink)(this.absolutePath);
});

@@ -130,3 +130,3 @@ }

var e_3, _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
destination = destination instanceof File ? destination : new File(destination);

@@ -136,3 +136,3 @@ if (yield this.isDirectory) {

try {
for (var _b = tslib_1.__asyncValues(this.descendants()), _c; _c = yield _b.next(), !_c.done;) {
for (var _b = (0, tslib_1.__asyncValues)(this.descendants()), _c; _c = yield _b.next(), !_c.done;) {
const descendant = _c.value;

@@ -153,3 +153,3 @@ yield descendant.copy(dest, flags);

destination = destination.child(this.name);
return yield util_1.promisify(fs.copyFile)(this.absolutePath, destination.absolutePath, flags);
return yield (0, util_1.promisify)(fs.copyFile)(this.absolutePath, destination.absolutePath, flags);
}

@@ -161,6 +161,6 @@ });

File.tempDirectory = new File(os.tmpdir());
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy
], File.prototype, "name", null);
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy

@@ -167,0 +167,0 @@ ], File.prototype, "url", null);

export declare function identity<T>(): (instance: T) => T;
export declare function get<R>(fun: () => R, defaultResult?: any): R;
//# sourceMappingURL=functions.d.ts.map

@@ -8,2 +8,1 @@ export declare function replace<T extends {}, K extends keyof T>(object: T, key: K, value: T[K]): T;

};
//# sourceMappingURL=lazy.d.ts.map
export declare function runningInNode(): boolean;
//# sourceMappingURL=node.d.ts.map

@@ -7,2 +7,1 @@ export declare function increment(a: number): number;

export declare const sum: (a: number, b: number) => number;
//# sourceMappingURL=numbers.d.ts.map

@@ -22,3 +22,4 @@ "use strict";

exports.subtract = subtract;
exports.sum = (a, b) => a + b;
const sum = (a, b) => a + b;
exports.sum = sum;
//# sourceMappingURL=numbers.js.map
{
"name": "@bodar/totallylazy",
"version": "0.467.309",
"description": "Totallylazy",
"repository": "git@github.com:bodar/totallylazy.js.git",
"version": "0.493.336",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com:bodar/totallylazy.js.git"
},
"author": "Daniel Worthington-Bodart <dan@bodar.com>",
"license": "Apache-2.0",
"private": false,
"scripts": {
"clean": "rm -rf build/artifacts",
"build": "tsc",
"generate": "ts-node src/money/generate-currencies.ts",
"test": "NODE_ENV=development NODE_ICU_DATA=./node_modules/full-icu TZ='America/Los_Angeles' yarn run mocha --require ts-node/register 'test/**/*.test.ts'",
"perf": "ts-node perf/trie.ts"
"bugs": {
"url": "https://github.com/bodar/totallylazy/issues"
},
"homepage": "https://github.com/bodar/totallylazy",
"publishConfig": {
"directory": "../dist",
"access": "public"
},
"files": [
"*.js",
"*.d.ts"
],
"dependencies": {
"tslib": "^2.0.1"
"tslib": "^2.3.1"
},
"devDependencies": {
"@types/benchmark": "^1.0.31",
"@types/chai": "^4.2.9",
"@types/libxmljs": "^0.18.5",
"@types/mocha": "^7.0.1",
"@types/node-fetch": "^2.5.5",
"@types/wikidata-sdk": "^5.15.1",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"libxmljs": "^0.19.7",
"mocha": "^7.1.0",
"mocha-headless-chrome": "^2.0.3",
"node-fetch": "^2.6.0",
"ts-node": "^8.6.2",
"typescript": "^4.0.3",
"wikidata-sdk": "^7.0.7"
"madge": "^5.0.1"
},

@@ -40,3 +33,9 @@ "optionalDependencies": {

"http-shutdown": "^1.2.2"
}
}
},
"scripts": {
"circular": "madge --extensions ts --circular .",
"generate": "esr money/generate-currencies.ts",
"perf": "esr perf/trie.ts"
},
"readme": "# TotallyLazy.js\n\n[![CircleCI](https://circleci.com/gh/bodar/totallylazy.js.svg?style=svg)](https://circleci.com/gh/bodar/totallylazy.js)\n[![npm version](https://badge.fury.io/js/%40bodar%2Ftotallylazy.svg)](https://badge.fury.io/js/%40bodar%2Ftotallylazy)\n\nLOTS STILL MISSING!\n\n * Written in Typescript\n * Targeting ESNext (if using JS you will need babel etc)\n * Transducers for both sync and async code\n * Extensive use of Promise, Iterators, Generators and AsyncIterators\n * Includes HTTP as a function (think minimal UtterlyIdle/HTTP4K)\n * Minimal dependencies (just polyfills if needed)\n \n TODO\n * SQL projections using the Transducers (think LINQ/LazyRecords)\n \n"
}
import { NamedMatch, NamedRegExp } from "./characters";
import { PrefixTree } from "./trie";
import { Comparator, Mapper } from "./collections";
import { Mapper } from "./collections";
export declare class NamedRegexParser implements Parser<NamedMatch[]> {

@@ -39,20 +38,2 @@ protected regex: NamedRegExp;

}
export interface Datum<V> {
name: string;
value: V;
}
export declare class DatumLookup<V> {
private readonly data;
private readonly prefixTree;
constructor(data: Datum<V>[], comparator?: Comparator<string>);
parse(value: string, strategy?: MatchStrategy<V>): V;
get pattern(): string;
get max(): number;
get characters(): string[];
}
export declare type MatchStrategy<V> = (prefixTree: PrefixTree<Datum<V>[]>, value: string) => V | undefined;
export declare function uniqueMatch<V>(prefixTree: PrefixTree<Datum<V>[]>, value: string): V | undefined;
export declare function prefer<V>(value: undefined): undefined;
export declare function prefer<V>(...values: V[]): MatchStrategy<V>;
export declare function infer(locale: string): MatchStrategy<string>;
export declare class OrParser<T> implements Parser<T> {

@@ -79,51 +60,2 @@ private readonly parsers;

}
export declare const boundaryDelimiters = ",.";
export declare const extraDelimiters = " -/";
export declare function cleanValue(value: string): string;
export declare function atBoundaryOnly(pattern: string): string;
export declare type Numeral = Datum<number>;
export declare class Numerals extends DatumLookup<number> {
private locale;
constructor(data: Datum<number>[], locale: string);
static cache: {
[key: string]: Numerals;
};
static get(locale: string, additionalData?: Numeral[]): Numerals;
static create(locale: string, additionalData?: Numeral[]): Numerals;
static generateData(locale: string): Numeral[];
parse(value: string): number;
format(value: number): string;
}
export declare const numberFormatter: (locale: string) => Intl.NumberFormat;
export declare const digits: (locale: string) => string;
export declare class Spaces {
static codes: string[];
static spaces: string;
static pattern: RegExp;
static handle(value: string): string;
}
export declare const numberPattern: (locale: string) => string;
export declare function mapIgnoreError<A, B>(mapper: Mapper<A, B>): import("./transducers").FlatMapTransducer<A, B>;
export declare function separatorsOf(amount: string): string[];
export declare type AllowedDecimalSeparators = '.' | ',' | '٫';
export declare function isDecimalSeparator(value: any): value is AllowedDecimalSeparators;
export declare function decimalSeparator(value: any): AllowedDecimalSeparators;
export declare class NumberParser implements Parser<number> {
private decimalSeparator;
private locale;
readonly strictNumberPattern: RegExp;
readonly globalNumberPattern: NamedRegExp;
constructor(decimalSeparator: (amount: string) => AllowedDecimalSeparators, locale: string);
parse(value: string): number;
parseAll(value: string): number[];
private parseSingle;
private convert;
private numberOf;
}
export declare type Locale = string;
export declare function numberParser(): Parser<number>;
export declare function numberParser(decimalSeparatorOrLocale: AllowedDecimalSeparators | Locale): Parser<number>;
export declare function numberParser(decimalSeparator: AllowedDecimalSeparators, locale: Locale): Parser<number>;
export declare const inferDecimalSeparator: (locale: string) => AllowedDecimalSeparators;
export declare function numberOf(value: string): number;
//# sourceMappingURL=parsing.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.numberOf = exports.inferDecimalSeparator = exports.numberParser = exports.NumberParser = exports.decimalSeparator = exports.isDecimalSeparator = exports.separatorsOf = exports.mapIgnoreError = exports.numberPattern = exports.Spaces = exports.digits = exports.numberFormatter = exports.Numerals = exports.atBoundaryOnly = exports.cleanValue = exports.extraDelimiters = exports.boundaryDelimiters = exports.CachingParser = exports.all = exports.AllParser = exports.parsers = exports.or = exports.OrParser = exports.infer = exports.prefer = exports.uniqueMatch = exports.DatumLookup = exports.FailParser = exports.IdentityParser = exports.mappingParser = exports.MappingParser = exports.preProcess = exports.PreProcessor = exports.namedRegexParser = exports.NamedRegexParser = void 0;
exports.extraDelimiters = exports.CachingParser = exports.all = exports.AllParser = exports.parsers = exports.or = exports.OrParser = exports.FailParser = exports.IdentityParser = exports.mappingParser = exports.MappingParser = exports.preProcess = exports.PreProcessor = exports.namedRegexParser = exports.NamedRegexParser = void 0;
const tslib_1 = require("tslib");
const characters_1 = require("./characters");
const trie_1 = require("./trie");
const arrays_1 = require("./arrays");
const collections_1 = require("./collections");
const transducers_1 = require("./transducers");
const cache_1 = require("./cache");
const preferred_currencies_1 = require("./money/preferred-currencies");
const functions_1 = require("./functions");
const array_1 = require("./array");
class NamedRegexParser {

@@ -24,3 +20,3 @@ constructor(regex) {

parseAll(value) {
return collections_1.array(this.regex.exec(value));
return (0, array_1.array)(this.regex.exec(value));
}

@@ -56,3 +52,3 @@ }

parse(value) {
return this.mapper(this.parser.parse(characters_1.removeUnicodeMarkers(value)));
return this.mapper(this.parser.parse((0, characters_1.removeUnicodeMarkers)(value)));
}

@@ -62,3 +58,3 @@ parseAll(value) {

return [];
return collections_1.array(this.parser.parseAll(characters_1.removeUnicodeMarkers(value)), transducers_1.flatMap(v => {
return (0, array_1.array)(this.parser.parseAll((0, characters_1.removeUnicodeMarkers)(value)), (0, transducers_1.flatMap)(v => {
try {

@@ -96,75 +92,2 @@ return [this.mapper(v)];

exports.FailParser = FailParser;
class DatumLookup {
constructor(data, comparator = trie_1.DEFAULT_COMPARATOR) {
this.data = data;
this.prefixTree = this.data.reduce((t, m) => {
const data = t.lookup(m.name) || [];
data.push(m);
return t.insert(m.name, data);
}, new trie_1.PrefixTree(undefined, comparator));
}
parse(value, strategy = uniqueMatch) {
const match = strategy(this.prefixTree, value);
if (typeof match === "undefined")
throw new Error(`${this.constructor.name} - Unable to parse: ${value}`);
return match;
}
get pattern() {
return `[${this.characters.join('')}]{1,${this.max}}`;
}
get max() {
return this.data.reduce((max, l) => {
const length = characters_1.characters(l.name).length;
return Math.max(max, length);
}, Number.MIN_VALUE);
}
get characters() {
return arrays_1.unique(arrays_1.flatten(this.data.map(d => d.name).map(characters_1.characters))).sort();
}
}
exports.DatumLookup = DatumLookup;
function uniqueMatch(prefixTree, value) {
const matches = arrays_1.flatten(prefixTree.match(value));
const data = arrays_1.unique(matches.map(d => d.value));
if (data.length != 1)
return undefined;
return data[0];
}
exports.uniqueMatch = uniqueMatch;
function prefer(...values) {
if (values.filter(Boolean).length === 0)
return undefined;
return (prefixTree, value) => {
const matches = prefixTree.lookup(value) || [];
const data = arrays_1.unique(matches.map(d => d.value));
if (data.length === 0)
return;
if (data.length === 1)
return data[0];
return data.find(m => values.indexOf(m) !== -1);
};
}
exports.prefer = prefer;
function localeParts(locale) {
if (!locale)
return [];
return locale.split(/[-_]/).filter(Boolean);
}
function infer(locale) {
const [, country] = localeParts(locale);
const preferred = preferred_currencies_1.PreferredCurrencies.for(country);
return (prefixTree, value) => {
const matches = prefixTree.lookup(value) || [];
const allCodes = arrays_1.unique(matches.map(d => d.value));
if (allCodes.length === 0)
return;
if (allCodes.length === 1)
return allCodes[0];
const bestMatch = allCodes.filter(iso => iso.startsWith(country));
if (bestMatch.length === 1)
return bestMatch[0];
return allCodes.find(m => preferred.indexOf(m) !== -1);
};
}
exports.infer = infer;
class OrParser {

@@ -212,3 +135,3 @@ constructor(parsers) {

parseAll(value) {
return arrays_1.flatten(this.parsers.map(p => p.parseAll(value)));
return this.parsers.flatMap(p => p.parseAll(value));
}

@@ -232,157 +155,10 @@ }

}
tslib_1.__decorate([
(0, tslib_1.__decorate)([
cache_1.cache
], CachingParser.prototype, "parse", null);
tslib_1.__decorate([
(0, tslib_1.__decorate)([
cache_1.cache
], CachingParser.prototype, "parseAll", null);
exports.CachingParser = CachingParser;
exports.boundaryDelimiters = ',.';
exports.extraDelimiters = ' -/';
const trailingDelimiters = new RegExp(`[${exports.boundaryDelimiters}]$`);
function cleanValue(value) {
return value.replace(trailingDelimiters, '');
}
exports.cleanValue = cleanValue;
function atBoundaryOnly(pattern) {
return `(?:^|\\s)${pattern}(?=[\\s${exports.boundaryDelimiters}]|$)`;
}
exports.atBoundaryOnly = atBoundaryOnly;
class Numerals extends DatumLookup {
constructor(data, locale) {
super(data);
this.locale = locale;
}
static get(locale, additionalData = []) {
return Numerals.cache[locale] = Numerals.cache[locale] || Numerals.create(locale, additionalData);
}
static create(locale, additionalData = []) {
return new Numerals([...Numerals.generateData(locale), ...additionalData], locale);
}
static generateData(locale) {
const digits = exports.numberFormatter(locale).format(1234567890).replace(/[,. '٬٫]/g, '');
return collections_1.array(characters_1.characters(digits), transducers_1.zip([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), transducers_1.map(([c, d]) => ({ name: c, value: d })));
}
parse(value) {
const number = numberOf(value);
return !isNaN(number) ? number : super.parse(value);
}
format(value) {
return exports.numberFormatter(this.locale).format(value);
}
}
exports.Numerals = Numerals;
Numerals.cache = {};
exports.numberFormatter = cache_1.caching((locale) => new Intl.NumberFormat(locale, { useGrouping: false }));
exports.digits = cache_1.caching((locale) => {
const characters = Numerals.get(locale).characters.join('');
if (characters === '0123456789')
return '\\d';
return `\\d${characters}`;
});
class Spaces {
static handle(value) {
return Spaces.codes.indexOf(value) != -1 ? Spaces.spaces : value;
}
}
exports.Spaces = Spaces;
Spaces.codes = [32, 160, 8239].map(code => String.fromCharCode(code));
Spaces.spaces = Spaces.codes.join('');
Spaces.pattern = new RegExp(`[${Spaces.spaces}]`, 'g');
const allowedSeparators = `٬٫,.'’‘${Spaces.spaces}`;
exports.numberPattern = cache_1.caching((locale) => {
const d = exports.digits(locale);
return `-?(?:[${d}]+[${allowedSeparators}])*[${d}]+`;
});
function mapIgnoreError(mapper) {
return transducers_1.flatMap((value) => {
try {
return [mapper(value)];
}
catch (e) {
return [];
}
});
}
exports.mapIgnoreError = mapIgnoreError;
const separatorsPattern = characters_1.NamedRegExp.create(`(?<separator>[${allowedSeparators}])`);
function separatorsOf(amount) {
return collections_1.array(separatorsPattern.exec(amount), transducers_1.map(([match]) => match.value));
}
exports.separatorsOf = separatorsOf;
function isDecimalSeparator(value) {
return value && typeof value === "string" && value === '.' || value === ',' || value === '٫';
}
exports.isDecimalSeparator = isDecimalSeparator;
function decimalSeparator(value) {
if (isDecimalSeparator(value))
return value;
throw new Error(`Invalid decimal separator${value}`);
}
exports.decimalSeparator = decimalSeparator;
class NumberParser {
constructor(decimalSeparator, locale) {
this.decimalSeparator = decimalSeparator;
this.locale = locale;
this.strictNumberPattern = new RegExp(`^${exports.numberPattern(locale)}$`);
this.globalNumberPattern = characters_1.NamedRegExp.create(`(?<number>${exports.numberPattern(locale)})`, 'g');
}
parse(value) {
if (!this.strictNumberPattern.test(value))
throw new Error(`Unable to parse '${value}'`);
return this.parseSingle(value);
}
parseAll(value) {
return collections_1.array(this.globalNumberPattern.exec(value), mapIgnoreError(([match]) => this.parseSingle(match.value.trim())));
}
parseSingle(value, decimalSeparator = this.decimalSeparator(value)) {
const separators = separatorsOf(value);
if (separators.length === 0)
return this.numberOf(value, decimalSeparator);
const lastSeparator = separators[separators.length - 1];
const groupSeparators = lastSeparator === decimalSeparator ? separators.slice(0, separators.length - 1) : separators;
if (groupSeparators.indexOf(decimalSeparator) !== -1)
throw new Error(`Unable to parse '${value}'`);
if (arrays_1.unique(groupSeparators).length > 1)
throw new Error(`Unable to parse '${value}'`);
return this.numberOf(value, decimalSeparator);
}
convert(value, decimalSeparator) {
const numerals = Numerals.get(this.locale);
return characters_1.characters(value).map(c => {
if (c === decimalSeparator)
return '.';
if (c === '-')
return '-';
const number = functions_1.get(() => numerals.parse(c));
if (isNaN(number))
return '';
return number.toString();
}).join('');
}
numberOf(value, decimalSeparator) {
const text = this.convert(value, decimalSeparator);
const result = numberOf(text);
if (isNaN(result)) {
throw new Error(`Unable to parse '${value}'`);
}
return result;
}
}
exports.NumberParser = NumberParser;
function numberParser(decimalSeparatorOrLocale, locale = 'en') {
if (!decimalSeparatorOrLocale)
return numberParser(locale);
if (isDecimalSeparator(decimalSeparatorOrLocale))
return new NumberParser(ignore => decimalSeparatorOrLocale, locale);
return numberParser(exports.inferDecimalSeparator(decimalSeparatorOrLocale), decimalSeparatorOrLocale);
}
exports.numberParser = numberParser;
exports.inferDecimalSeparator = cache_1.caching((locale) => functions_1.get(() => decimalSeparator(new Intl.NumberFormat(locale).formatToParts(.1).find(e => e.type === 'decimal').value), '.'));
function numberOf(value) {
if (!value || value.trim().length === 0)
return NaN;
return Number(value);
}
exports.numberOf = numberOf;
//# sourceMappingURL=parsing.js.map

@@ -31,2 +31,1 @@ export declare function match<T, R>(instance: T, ...matchers: Matcher<T, R>[]): R;

export declare function apply<T>(instance: T, pattern: Pattern<T>): Matched<T> | undefined;
//# sourceMappingURL=pattern.d.ts.map

@@ -9,2 +9,1 @@ import { Mapper } from "./collections";

export declare function where<A, B>(mapper: Mapper<A, B>, predicate: Predicate<B>): Where<A, B>;
//# sourceMappingURL=predicates.d.ts.map
export declare function call<T, S>(value: S): any;
export declare function on<T>(instance: new () => T): T;
//# sourceMappingURL=proxy.d.ts.map

@@ -8,2 +8,1 @@ /// <reference types="node" />

export declare function run(options: RunOptions): AsyncIterable<string>;
//# sourceMappingURL=run.d.ts.map

@@ -8,3 +8,3 @@ "use strict";

const handler = new collections_1.AsyncIteratorHandler();
const process = child_process_1.spawn(options.command, options.arguments || [], Object.assign(Object.assign({}, options), { stdio: ['ignore', 'pipe', 'pipe'] }));
const process = (0, child_process_1.spawn)(options.command, options.arguments || [], Object.assign(Object.assign({}, options), { stdio: ['ignore', 'pipe', 'pipe'] }));
process.stdout.on('data', (data) => handler.value(data.toString()));

@@ -11,0 +11,0 @@ process.stderr.on('data', (data) => handler.value(data.toString()));

@@ -0,3 +1,3 @@

import { IterableLike } from "./collections";
import { Transducer } from "./transducers";
import { IterableLike } from "./collections";
export declare function iterate<T>(generator: (t: T) => T, value: T): Iterable<T>;

@@ -30,2 +30,1 @@ export declare function repeat<T>(generator: () => T): Iterable<T>;

}
//# sourceMappingURL=sequence.d.ts.map

@@ -5,4 +5,4 @@ "use strict";

const numbers_1 = require("./numbers");
const collections_1 = require("./collections");
const transducers_1 = require("./transducers");
const collections_1 = require("./collections");
function* iterate(generator, value) {

@@ -25,3 +25,3 @@ while (true) {

if (end === undefined) {
yield* iterate(numbers_1.add(step), start);
yield* iterate((0, numbers_1.add)(step), start);
}

@@ -31,5 +31,5 @@ else {

if (end < start)
yield* sequence(iterate(numbers_1.subtract(absolute), start), transducers_1.takeWhile(n => n >= end));
yield* sequence(iterate((0, numbers_1.subtract)(absolute), start), (0, transducers_1.takeWhile)(n => n >= end));
else
yield* sequence(iterate(numbers_1.add(absolute), start), transducers_1.takeWhile(n => n <= end));
yield* sequence(iterate((0, numbers_1.add)(absolute), start), (0, transducers_1.takeWhile)(n => n <= end));
}

@@ -39,7 +39,7 @@ }

function sequence(source, ...transducers) {
if (collections_1.isIterable(source)) {
if ((0, collections_1.isIterable)(source)) {
return new Sequence(source, transducers);
}
if (collections_1.isArrayLike(source)) {
return new Sequence(collections_1.iterable(source), transducers);
if ((0, collections_1.isArrayLike)(source)) {
return new Sequence((0, collections_1.iterable)(source), transducers);
}

@@ -46,0 +46,0 @@ return new AsyncSequence(source, transducers);

@@ -63,2 +63,1 @@ import { characters } from "./characters";

}
//# sourceMappingURL=trie.d.ts.map

@@ -9,4 +9,7 @@ "use strict";

const avltree_1 = require("./avltree");
const sequence_1 = require("./sequence");
const transducers_1 = require("./transducers");
const sequence_1 = require("./sequence");
const transducers_2 = require("./transducers");
const transducers_3 = require("./transducers");
const transducers_4 = require("./transducers");
class TrieFactory {

@@ -32,6 +35,6 @@ constructor(comparator = collections_1.ascending) {

}
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy
], TrieFactory.prototype, "avlTree", null);
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy

@@ -61,3 +64,3 @@ ], TrieFactory.prototype, "empty", null);

if (key.length == 0)
return collections_1.single(this.children.values(), transducers_1.reduce((a, t) => {
return (0, transducers_1.single)(this.children.values(), (0, transducers_4.reduce)((a, t) => {
return a.concat(t.match(key));

@@ -93,3 +96,3 @@ }, this.value ? [this.value] : []));

function recurseChildren(trie, prefix) {
return sequence_1.sequence(trie.children.entries(), transducers_1.flatMap(entry => recurse(prefix, entry)));
return (0, sequence_1.sequence)(trie.children.entries(), (0, transducers_3.flatMap)(entry => recurse(prefix, entry)));
}

@@ -99,9 +102,9 @@ return recurseChildren(this, []);

keys() {
return sequence_1.sequence(this.entries(), transducers_1.map(([key]) => key));
return (0, sequence_1.sequence)(this.entries(), (0, transducers_2.map)(([key]) => key));
}
values() {
return sequence_1.sequence(this.entries(), transducers_1.map(([, value]) => value));
return (0, sequence_1.sequence)(this.entries(), (0, transducers_2.map)(([, value]) => value));
}
get height() {
return collections_1.single(this.children.values(), transducers_1.reduce((a, c) => Math.max(a, c.height + 1), 0));
return (0, transducers_1.single)(this.children.values(), (0, transducers_4.reduce)((a, c) => Math.max(a, c.height + 1), 0));
}

@@ -112,6 +115,6 @@ toString() {

}
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy
], Trie.prototype, "isEmpty", null);
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy

@@ -152,9 +155,9 @@ ], Trie.prototype, "height", null);

entries() {
return sequence_1.sequence(this.trie.entries(), transducers_1.map(([chars, value]) => pair(chars.join(''), value)));
return (0, sequence_1.sequence)(this.trie.entries(), (0, transducers_2.map)(([chars, value]) => pair(chars.join(''), value)));
}
keys() {
return sequence_1.sequence(this.entries(), transducers_1.map(([key]) => key));
return (0, sequence_1.sequence)(this.entries(), (0, transducers_2.map)(([key]) => key));
}
values() {
return sequence_1.sequence(this.entries(), transducers_1.map(([, value]) => value));
return (0, sequence_1.sequence)(this.entries(), (0, transducers_2.map)(([, value]) => value));
}

@@ -166,3 +169,3 @@ get height() {

const empty = Row.create(this.converter(key), this.comparator);
return collections_1.single(this.trie.children.entries(), transducers_1.reduce((a, [letter, value]) => {
return (0, transducers_1.single)(this.trie.children.entries(), (0, transducers_4.reduce)((a, [letter, value]) => {
return a.concat(recurse(value, letter, empty, maxDist));

@@ -173,6 +176,6 @@ }, []));

}
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy
], PrefixTree.prototype, "isEmpty", null);
tslib_1.__decorate([
(0, tslib_1.__decorate)([
lazy_1.lazy

@@ -188,3 +191,3 @@ ], PrefixTree.prototype, "height", null);

if (currentRow.minimal <= maxDist) {
return collections_1.single(trie.children.entries(), transducers_1.reduce((a, [letter, value]) => {
return (0, transducers_1.single)(trie.children.entries(), (0, transducers_4.reduce)((a, [letter, value]) => {
return a.concat(recurse(value, letter, currentRow, maxDist));

@@ -191,0 +194,0 @@ }, result));

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