@nodesecure/contact
v3.3.0
Published
Utilities to extract/fetch data on NPM contacts (author, maintainers ..)
Readme
Requirements
- Node.js v24 or higher
Getting Started
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @nodesecure/contact
# or
$ yarn add @nodesecure/contactUsage example
Here is an example of usage from the Scanner. In this case, we are using dependenciesMap, which is a Record<string, Dependency>. However, you can build your own record of ContactExtractorPackageMetadata.
import {
ContactExtractor,
type ContactExtractorPackageMetadata
} from "@nodesecure/contact";
const dependencies: Record<string, ContactExtractorPackageMetadata> = Object.create(null);
for (const [packageName, dependency] of dependenciesMap) {
const { author, maintainers } = dependency.metadata;
dependencies[packageName] = {
maintainers,
...( author === null ? {} : { author } )
}
}
const extractor = new ContactExtractor({
highlight: [
{
name: "Sindre Sorhus"
}
]
});
const { illuminated, expired } = extractor.fromDependencies(
dependencies
);
console.log({ illuminated, expired });API
- NsResolver
- Utilities (compareContact, toContactWithMetadata, extractMetadataContacts, parseRegExp)
Contact is defined by the following TypeScript interface:
interface Contact {
email?: string;
url?: string;
name: string;
}ContactExtractor
The constructor take a list of contacts you want to find/extract.
interface ContactExtractorOptions {
highlight: EnforcedContact[];
}
type EnforcedContact = RequireAtLeastOne<
Contact,
"name" | "email"
>;[!TIP] This package authorizes literal RegExp in the name property of
highlightcontacts
The methods fromDependencies and fromManifest will return an Array of IlluminatedContact objects if any are found in the provided dependencies and the list of expired email domains.
interface ContactExtractorFromDependenciesResult {
illuminated: IlluminatedContact[];
/**
* List of email domains that are expired
*/
expired: string[];
}
type IlluminatedContact = ContactWithMetadata & {
dependencies: string[];
}
export type ContactFlag = "free-email-service";
export interface ContactWithMetadata extends Contact {
flags: ContactFlag[];
}
License
MIT
