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

relevant-urban

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relevant-urban - npm Package Compare versions

Comparing version 1.3.5 to 2.0.0

Constants.js

14

package.json
{
"name": "relevant-urban",
"version": "1.3.5",
"version": "2.0.0",
"description": "Urban Dictionary API wrapper made for everyone with useful methods using promises and snekfetch",

@@ -17,12 +17,12 @@ "main": "urban.js",

"dependencies": {
"snekfetch": "^2.2.0"
"snekfetch": "^3.0.1"
},
"devDependencies": {
"eslint": "^3.19.0",
"ava": "^0.19.1"
"ava": "^0.19.1",
"eslint": "^3.19.0"
},
"scripts": {
"test": "npm run lint && npm run check",
"lint": "eslint urban.js test/",
"lint:fix": "eslint --fix urban.js test/",
"lint": "eslint urban.js Constants.js test/",
"lint:fix": "eslint --fix urban.js Constants.js test/",
"check": "node_modules/.bin/ava -v"

@@ -37,2 +37,2 @@ },

}
}
}

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

# Relevant urban [![Build Status](https://travis-ci.org/SnekLab/relevant-urban.svg?branch=master)](https://travis-ci.org/SnekLab/relevant-urban) [![NPM](https://nodei.co/npm/relevant-urban.png?mini=true)](https://nodei.co/npm/relevant-urban/)
# Relevant urban [![NPM](https://nodei.co/npm/relevant-urban.png?mini=true)](https://nodei.co/npm/relevant-urban/) [![Build Status](https://travis-ci.org/SnekLab/relevant-urban.svg?branch=master)](https://travis-ci.org/SnekLab/relevant-urban) [![Greenkeeper badge](https://badges.greenkeeper.io/SnekLab/relevant-urban.svg)](https://greenkeeper.io/)
<p align="center">

@@ -3,0 +4,0 @@ <img src="https://github.com/SnekLab/relevant-urban/blob/master/ud.png?raw=true" alt="Urban Dictionary API wrapper logo"/>

@@ -6,18 +6,18 @@ const urban = require('../urban.js');

.then(d => t.truthy(d))
.catch(e => t.falsy(e)));
.catch(e => t.truthy(e)));
test('Fetching \'hello\' urban definition', t => urban('hello')
.then(d => t.truthy(d))
.catch(e => t.falsy(e)));
.catch(e => t.truthy(e)));
test('Fetching \'fsiojgjsgjsgihsghghjsh\' urban definition (success if not found)', t => urban('fsiojgjsgjsgihsghghjsh')
.then(d => t.falsy(d))
.catch(e => t.falsy(e)));
.catch(e => t.truthy(e)));
test('Fetching random specific urban definition', t => urban.random('hello')
.then(d => t.truthy(d))
.catch(e => t.falsy(e)));
.catch(e => t.truthy(e)));
test('Fetching all specific urban definitions', t => urban.all('hello')
.then(d => t.true(typeof d == 'object'))
.catch(e => t.falsy(e)));
.catch(e => t.truthy(e)));
const snekfetch = require('snekfetch');
const api = 'https://api.urbandictionary.com/v0';
const ArrayRandom = array => array[Math.floor(Math.random() * array.length)];
const { BASE_URL, DEFINITION, randomArrayItem } = require('./Constants');
function search(query, page = 1) {
return new snekfetch('GET', `${api}/define?page=${page}&term=${query}`)
.then(res => res.body)
.then(body => body.result_type == 'no_results' ? Promise.reject(null) : body);
}
class Urban {
static first(query) {
return this.search(query)
.then(body => new DEFINITION(body.list[0], body));
}
static random(query = null) {
if (!query) return this.getRandom(query)
.then(body => new DEFINITION(body.list[0], body));
else return this.search(query)
.then(body => new DEFINITION(randomArrayItem(body.list), body));
}
static all(query) {
return this.search(query)
.then(body => body.list.map(d => new DEFINITION(d, body)));
}
static search(query, page = 1) {
return new snekfetch('GET', `${BASE_URL}/define?page=${page}&term=${query}`)
.then(res => res.body && res.body.result_type != 'no_results' ? res.body : Promise.reject(TypeError('No results')));
}
static getRandom() {
return new snekfetch('GET', `${BASE_URL}/random`)
.then(res => res.body && res.body.result_type != 'no_results' ? res.body : Promise.reject(TypeError('No results')));
}
static get version() {
return require('./package.json').version;
}
function first(query) {
return search(query)
.then(body => body ?
Object.assign(new Definition(body.list[0]), {
tags: Array.from(new Set(body.tags)),
sounds: body.sounds
}) : Promise.reject(null));
}
function all(query) {
return search(query)
.then(body => body ?
Object.assign(body.list.map(d => new Definition(d)), {
tags: Array.from(new Set(body.tags)),
sounds: body.sounds
}) : Promise.reject(null));
}
function random(query = null) {
if (!query) return new snekfetch('GET', `${api}/random`)
.then(res => res.body)
.then(body => body.result_type == 'no_results' ? null : new Definition(body.list[0]));
else return search(query)
.then(body => body ?
Object.assign(new Definition(ArrayRandom(body.list)), {
tags: Array.from(new Set(body.tags)),
sounds: body.sounds
}) : Promise.reject(null));
}
class Definition {
constructor({
defid,
word,
definition,
example,
permalink,
thumbs_up,
author,
thumbs_down
}) {
/**
* ID of definition.
* @type {number}
*/
this.id = defid;
/**
* Word used for definition.
* @type {string}
*/
this.word = word;
/**
* Definition itself.
* @type {string}
*/
this.definition = definition;
/**
* Definition example.
* @type {string}
*/
this.example = example;
/**
* Definition URL.
* @type {string}
*/
this.urbanURL = permalink;
/**
* Definition author name.
* @type {string}
*/
this.author = author;
/**
* Definition thumbs up.
* @type {number}
*/
this.thumbsUp = thumbs_up;
/**
* Definition thumbs down.
* @type {number}
*/
this.thumbsDown = thumbs_down;
}
}
module.exports = Object.assign(first, {
all,
random,
search,
version: require('./package.json').version
});
module.exports = Object.assign(Urban.first.bind(Urban), {
search: Urban.search,
definition: DEFINITION,
all: Urban.all.bind(Urban),
random: Urban.random.bind(Urban),
version: Urban.version });
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