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

@ts-common/string-map

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-common/string-map - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

25

index.d.ts

@@ -1,23 +0,18 @@

export interface StringMap<T> {
readonly [key: string]: T;
}
import { Tuple2 } from "@ts-common/tuple";
export declare const enum EntryIndex {
Name = 0,
Key = 0,
Value = 1
}
export interface Entry<T> {
readonly [EntryIndex.Name]: string;
readonly [EntryIndex.Value]: T;
/**
* The property is required for destruction.
*/
readonly [Symbol.iterator]: () => IterableIterator<string | T>;
export declare type Entry<T> = Tuple2<string, T>;
export declare const entry: <T>(key: string, value: T) => Entry<T>;
export declare function entryKey<T>(e: Entry<T>): string;
export declare function entryValue<T>(e: Entry<T>): T;
export interface StringMap<T> {
readonly [key: string]: T;
}
export declare function allKeys<T>(input: StringMap<T | undefined>): Iterable<string>;
export declare function entries<T>(input: StringMap<T | undefined>): Iterable<Entry<T>>;
export declare function names<T>(input: StringMap<T>): Iterable<string>;
export declare function keys<T>(input: StringMap<T>): Iterable<string>;
export declare function values<T>(input: StringMap<T | undefined>): Iterable<T>;
export declare function entry<T>(name: string, value: T): Entry<T>;
export declare function entryName<T>(e: Entry<T>): string;
export declare function entryValue<T>(e: Entry<T>): T;
export declare function groupBy<T>(input: Iterable<Entry<T>>, reduceFunc: (a: T, b: T) => T): StringMap<T>;
export declare function stringMap<T>(input: Iterable<Entry<T>>): StringMap<T>;

57

index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const i = tslib_1.__importStar(require("@ts-common/iterator"));
function entries(input) {
const _ = tslib_1.__importStar(require("@ts-common/iterator"));
const tuple_1 = require("@ts-common/tuple");
exports.entry = tuple_1.tuple2;
function entryKey(e) {
return e[0 /* Key */];
}
exports.entryKey = entryKey;
function entryValue(e) {
return e[1 /* Value */];
}
exports.entryValue = entryValue;
function allKeys(input) {
function* iterator() {
/* tslint:disable-next-line:no-loop-statement */
for (const name in input) {
const value = input[name];
/* tslint:disable-next-line:no-if-statement */
if (value !== undefined) {
yield entry(name, value);
}
for (const key in input) {
yield key;
}
}
return i.iterable(iterator);
return _.iterable(iterator);
}
exports.allKeys = allKeys;
function entries(input) {
return _.filterMap(allKeys(input), key => {
const value = input[key];
return value !== undefined ? exports.entry(key, value) : undefined;
});
}
exports.entries = entries;
function names(input) {
return i.map(entries(input), entryName);
function keys(input) {
return _.map(entries(input), entryKey);
}
exports.names = names;
exports.keys = keys;
function values(input) {
return i.map(entries(input), entryValue);
return _.map(entries(input), entryValue);
}
exports.values = values;
function entry(name, value) {
return [name, value];
}
exports.entry = entry;
function entryName(e) {
return e[0 /* Name */];
}
exports.entryName = entryName;
function entryValue(e) {
return e[1 /* Value */];
}
exports.entryValue = entryValue;
function groupBy(input, reduceFunc) {
/* tslint:disable-next-line:readonly-keyword */
const result = {};
i.forEach(input, ([name, value]) => {
const prior = result[name];
_.forEach(input, ([key, value]) => {
const prior = result[key];
/* tslint:disable-next-line:no-object-mutation no-expression-statement */
result[name] = prior === undefined ? value : reduceFunc(prior, value);
result[key] = prior === undefined ? value : reduceFunc(prior, value);
});

@@ -47,0 +48,0 @@ return result;

{
"name": "@ts-common/string-map",
"version": "0.0.3",
"version": "0.0.4",
"description": "",

@@ -36,4 +36,5 @@ "main": "index.js",

"dependencies": {
"@ts-common/iterator": "0.0.21"
"@ts-common/iterator": "0.0.21",
"@ts-common/tuple": "0.0.0"
}
}
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