update to working search
This commit is contained in:
@ -2,5 +2,3 @@ import * as plugins from './smartnpm.plugins'
|
||||
|
||||
export * from './smartnpm.classes.npmregistry'
|
||||
export * from './smartnpm.classes.npmpackage'
|
||||
|
||||
export let standardExport = 'Hi there! :) This is a exported string'
|
||||
|
@ -1,7 +1,40 @@
|
||||
import * as plugins from './smartnpm.plugins'
|
||||
|
||||
export class NpmPackage {
|
||||
search (searchObject: ISearchObject) {
|
||||
let response = await plugins.Smartrequest
|
||||
name: string = null
|
||||
scope: string = null
|
||||
version: string = null
|
||||
description: string = null
|
||||
keywords: string[] = null
|
||||
date: '2017-08-02T11:22:49.144Z'
|
||||
links: {
|
||||
npm: string
|
||||
homepage: string
|
||||
repository: string
|
||||
bugs: string
|
||||
} = null
|
||||
author: {
|
||||
name: 'Lossless GmbH'
|
||||
} = null
|
||||
publisher: {
|
||||
username: 'gitzone', email: 'npm@git.zone'
|
||||
} = null
|
||||
maintainers: any = null
|
||||
score: {
|
||||
final: number,
|
||||
detail: {
|
||||
quality: number,
|
||||
popularity: number,
|
||||
maintenance: number
|
||||
}
|
||||
} = null
|
||||
searchScore: number = null
|
||||
|
||||
constructor (descriptionArg) {
|
||||
for (let key in descriptionArg) {
|
||||
if (this[key] === null) {
|
||||
this[key] = descriptionArg[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,27 @@
|
||||
import * as plugins from './smartnpm.plugins'
|
||||
|
||||
interface ISearchObject {
|
||||
// metadata
|
||||
author?: string
|
||||
maintainer: string
|
||||
scope?: string
|
||||
keywords: string[]
|
||||
|
||||
// status
|
||||
deprecated?: boolean
|
||||
unstable?: boolean
|
||||
insecure?: boolean
|
||||
|
||||
// search behaviour
|
||||
boostExact: boolean
|
||||
scoreEffect: number
|
||||
// interfaces
|
||||
import { ISearchObject } from './smartnpm.interfaces'
|
||||
|
||||
// Analytics
|
||||
qualityWeight: number
|
||||
popularityWeight: number
|
||||
maintenanceWeight: number
|
||||
}
|
||||
// classes
|
||||
import { NpmPackage } from './smartnpm.classes.npmpackage'
|
||||
|
||||
export class NpmRegistry {
|
||||
private searchDomain = 'https://api.npms.io/v2/search?q='
|
||||
search (searchObjectArg: ISearchObject) {
|
||||
async search (searchObjectArg: ISearchObject) {
|
||||
let searchString = ''
|
||||
let addToSearchString = (addStringArg: string) => {
|
||||
searchString = `${searchString} ${addStringArg}`
|
||||
searchString = `${searchString}+${addStringArg}`
|
||||
}
|
||||
|
||||
// name
|
||||
if (searchObjectArg.name) { searchString = `${searchObjectArg.name}` }
|
||||
|
||||
// metadata
|
||||
if (searchObjectArg.author) { addToSearchString(`author:${searchObjectArg.author}`) }
|
||||
if (searchObjectArg.maintainer) { addToSearchString(`maintainer:${searchObjectArg.maintainer}`) }
|
||||
if (searchObjectArg.scope) { addToSearchString(`scope:${searchObjectArg.scope}`) }
|
||||
|
||||
|
||||
// status
|
||||
if (searchObjectArg.deprecated) {
|
||||
if (searchObjectArg.deprecated === true) {
|
||||
@ -57,16 +44,29 @@ export class NpmRegistry {
|
||||
addToSearchString(`not:insecure`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// search behaviour
|
||||
if (searchObjectArg.boostExact) { addToSearchString(`boost-exact:${searchObjectArg.boostExact}`) }
|
||||
if (searchObjectArg.scoreEffect) { addToSearchString(`score-effect:${searchObjectArg.scoreEffect}`) }
|
||||
|
||||
|
||||
// analytics
|
||||
if (searchObjectArg.qualityWeight) { addToSearchString(`author:${searchObjectArg.qualityWeight}`) }
|
||||
if (searchObjectArg.popularityWeight) { addToSearchString(`author:${searchObjectArg.popularityWeight}`) }
|
||||
if (searchObjectArg.maintenanceWeight) { addToSearchString(`author:${searchObjectArg.maintenanceWeight}`) }
|
||||
|
||||
let response = (await plugins.smartrequest.get(this.searchDomain, {}))
|
||||
plugins.beautylog.log(`Search for "${searchString}" on npm`)
|
||||
|
||||
let response = (await plugins.smartrequest.get(this.searchDomain + searchString, {}))
|
||||
let body: any = response.body
|
||||
|
||||
// lets create the response
|
||||
let packageArray: NpmPackage[] = []
|
||||
|
||||
for (let packageArg of body.results) {
|
||||
let localPackage = new NpmPackage(packageArg.package)
|
||||
packageArray.push(localPackage)
|
||||
}
|
||||
|
||||
return packageArray
|
||||
}
|
||||
}
|
||||
|
25
ts/smartnpm.interfaces.ts
Normal file
25
ts/smartnpm.interfaces.ts
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
export interface ISearchObject {
|
||||
// name
|
||||
name?: string
|
||||
|
||||
// metadata
|
||||
author?: string
|
||||
maintainer?: string
|
||||
scope?: string
|
||||
keywords?: string[]
|
||||
|
||||
// status
|
||||
deprecated?: boolean
|
||||
unstable?: boolean
|
||||
insecure?: boolean
|
||||
|
||||
// search behaviour
|
||||
boostExact?: boolean
|
||||
scoreEffect?: number
|
||||
|
||||
// Analytics
|
||||
qualityWeight?: number
|
||||
popularityWeight?: number
|
||||
maintenanceWeight?: number
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
import 'typings-global'
|
||||
|
||||
import * as beautylog from 'beautylog'
|
||||
import * as smartrequest from 'smartrequest'
|
||||
|
||||
export {
|
||||
beautylog,
|
||||
smartrequest
|
||||
}
|
||||
|
Reference in New Issue
Block a user