Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-kids-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/contact": major
---

Add new EnforcedContact type that allow either name or email to be highlighted
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions workspaces/contact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"build": "tsc -b",
"prepublishOnly": "npm run build",
"test-only": "tsx --test ./test/**/*.spec.ts",
"test": "c8 -r html npm run test-only"
"test": "c8 -r html npm run test-only",
"test:tsd": "npm run build && tsd"
},
"files": [
"dist"
Expand All @@ -36,6 +37,10 @@
"@faker-js/faker": "^9.7.0"
},
"dependencies": {
"@nodesecure/npm-types": "^1.2.0"
"@nodesecure/npm-types": "^1.2.0",
"type-fest": "^4.41.0"
},
"tsd": {
"directory": "test/types"
}
}
10 changes: 7 additions & 3 deletions workspaces/contact/src/ContactExtractor.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ import type { Contact } from "@nodesecure/npm-types";
// Import Internal Dependencies
import {
UnlitContact,
type EnforcedContact,
type IlluminatedContact
} from "./UnlitContact.class.js";

export type { IlluminatedContact };
export type {
IlluminatedContact,
EnforcedContact
};

export interface ContactExtractorPackageMetadata {
author?: Contact;
maintainers: Contact[];
}

export interface ContactExtractorOptions {
highlight: Contact[];
highlight: EnforcedContact[];
}

export class ContactExtractor {
private highlighted: Contact[] = [];
private highlighted: EnforcedContact[] = [];

constructor(
options: ContactExtractorOptions
Expand Down
12 changes: 9 additions & 3 deletions workspaces/contact/src/UnlitContact.class.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
// Import Third-party Dependencies
import type { Contact } from "@nodesecure/npm-types";
import type { RequireAtLeastOne } from "type-fest";

// Import Internal Dependencies
import * as utils from "./utils/index.js";

export type IlluminatedContact = Contact & {
export type EnforcedContact = RequireAtLeastOne<
Contact,
"name" | "email"
>;

export type IlluminatedContact = EnforcedContact & {
dependencies: string[];
};

export class UnlitContact {
private illuminated: Contact;
private illuminated: EnforcedContact;
private extendedName: RegExp | null = null;

public dependencies = new Set<string>();

constructor(
contact: Contact
contact: EnforcedContact
) {
this.illuminated = structuredClone(contact);
this.extendedName = typeof contact.name === "string" ?
Expand Down
4 changes: 2 additions & 2 deletions workspaces/contact/src/utils/compareContact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export interface CompareOptions {
* - add options for custom/advanced comparaison
*/
export function compareContact(
contactA: Contact,
contactB: Contact,
contactA: Partial<Contact>,
contactB: Partial<Contact>,
options: CompareOptions = Object.create(null)
): boolean {
const { compareName = true } = options;
Expand Down
16 changes: 16 additions & 0 deletions workspaces/contact/test/types/ContactExtractor.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Import Third-party Dependencies
import {
expectType
} from "tsd";

// Import Internal Dependencies
import {
ContactExtractor
} from "../../dist/index.js";

expectType<ContactExtractor>(new ContactExtractor({
highlight: [
{ email: "foo" },
{ name: "bar" }
]
}));
3 changes: 1 addition & 2 deletions workspaces/mama/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"object-hash": "^3.0.0"
},
"devDependencies": {
"@types/object-hash": "^3.0.6",
"tsd": "^0.32.0"
"@types/object-hash": "^3.0.6"
},
"tsd": {
"directory": "test/types"
Expand Down