Socket
Socket
Sign inDemoInstall

@empathyco/x-utils

Package Overview
Dependencies
1
Maintainers
5
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0-alpha.1 to 0.1.0-alpha.2

dist/cjs/types/paths.types.js

1

dist/cjs/types/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./paths.types"), exports);
tslib_1.__exportStar(require("./utils.types"), exports);
//# sourceMappingURL=index.js.map

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

export * from './paths.types';
export * from './utils.types';
//# sourceMappingURL=index.js.map

8

package.json
{
"name": "@empathyco/x-utils",
"version": "0.1.0-alpha.1",
"version": "0.1.0-alpha.2",
"description": "A utility package for Empathy search",

@@ -25,3 +25,4 @@ "author": "Empathy Systems Corporation S.L.",

"scripts": {
"build": "tsc && tsc --project tsconfig.esm.json",
"prebuild": "rimraf ./dist ./types",
"build": "tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json",
"test": "jest",

@@ -37,2 +38,3 @@ "postbuild": "npm pack",

"jest": "~27.3.1",
"rimraf": "~3.0.2",
"ts-jest": "~27.0.7",

@@ -44,3 +46,3 @@ "typescript": "~4.6.2"

},
"gitHead": "000bd96f2ef62864203dcf32968d00c4bd1cd992"
"gitHead": "2b748d5fbc023e808377fb25b8b050faea59b8da"
}

@@ -0,1 +1,2 @@

export * from './paths.types';
export * from './utils.types';
/**
* Retrieves the keys of a determinate type from a provided interface.
*
* @param SomeObject - The object to extract the keys from.
* @param Type - The type of the keys to be extracted.
*
* @internal
*/
declare type Keys<SomeObject, Type> = Extract<keyof SomeObject, Type>;
/**
* TypeScript type primitives. Basically every type possible except objects or arrays.

@@ -17,61 +8,9 @@ *

/**
* All the possible string paths to properties for a given object.
* Retrieves the keys of a determinate type from a provided interface.
*
* @param SomeObject - The object type to extract the properties names from.
* @example
* ```typescript
* interface Result {
* id: string,
* price: {
* max: number,
* min: number
* },
* images: string[]
* }
* @param SomeObject - The object to extract the keys from.
* @param Type - The type of the keys to be extracted.
*
* type ResultPropertyPaths = PropertyPath<Result>;
* // "id" | "price" | "price.max" | "price.min" | "images" | `images.${number}`;
* ```
* @remarks
* Be careful when using Records where the key name is typed only as string,
* since this type will not be able to infer the key name. Use always a union type with all the
* potential key name values when possible.
*
* When trying to get the path to an array item, keep in mind that a number ending with a dot is a
* valid javascript syntax so this type will assume as safe getting the 'n.' element.
* @public
*/
export declare type PropertyPath<SomeObject> = SomeObject extends (infer ArrayType)[] ? `${number}` | `${number}.${PropertyPath<ArrayType>}` : Keys<SomeObject, string> | NestedPropertyPath<SomeObject, Keys<SomeObject, string>>;
/**
* String path for child properties from a given object.
*
* @param SomeObject - The object type to extract the properties names from.
* @param PropName - Name of the property to get the path from.
*
* @internal
*/
declare type NestedPropertyPath<SomeObject, PropName extends string> = PropName extends keyof SomeObject ? SomeObject[PropName] extends SomeObject ? `${PropName}.${Keys<SomeObject[PropName], string>}${any}` : SomeObject[PropName] extends SomeObject[] ? `${PropName}.${number}` | `${PropName}.${number}.${Keys<SomeObject, string>}${any}` : `${PropName}.${PropertyPath<Exclude<SomeObject[PropName], Function | Primitive>>}` : never;
/**
* Retrieves type of property for the given path from the provided object.
*
* @param SomeObject - The object to extract the property type from.
* @param Path - String property path.
* @example
* ```typescript
* interface Result {
* id: string,
* price: {
* max: number,
* min: number
* },
* images: string[]
* }
*
* type MaxPrice = PropertyType<Result, "price.max">; // number
* type FirstImageType = PropertyType<Result, "images.0">; // string
* ```
*
* @public
*/
export declare type PropertyType<SomeObject, Path extends PropertyPath<SomeObject>> = Path extends keyof SomeObject ? SomeObject[Path] : Path extends `${infer Property}.${infer RemainingPath}` ? PropertyType<SomeObject[keyof SomeObject & Property], PropertyPath<SomeObject[keyof SomeObject & Property]> & RemainingPath> : SomeObject extends any[] ? SomeObject[number] : never;
export {};
export declare type Keys<SomeObject, Type> = Extract<keyof SomeObject, Type>;

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc