-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Layout rework
- Loading branch information
Showing
14 changed files
with
158 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
./src/README.md | ||
./lib/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'dotenv' | ||
|
||
/** Utils to setup your config */ | ||
|
||
/** | ||
* Get API Key | ||
* @returns {string} key | ||
*/ | ||
export function getKey() { | ||
if (Deno.env.has('WORDNIK_KEY')) { | ||
const key = 'api_key=' + Deno.env.get('WORDNIK_KEY') | ||
return key | ||
} else { | ||
console.error('No API key found!') | ||
} | ||
} | ||
|
||
/** | ||
* Get API Version | ||
* @returns {string} version | ||
*/ | ||
export function getVersion() { | ||
if (Deno.env.has('API_VERSION')) { | ||
const version = 'v' + Deno.env.get('API_VERSION') + '/' | ||
return version | ||
} else if (!Deno.env.has('API_VERSION')) { | ||
const version = 'v4/' // update when new api version comes out | ||
return version | ||
} | ||
} | ||
|
||
export class Wordnik { | ||
constructor() { | ||
/** | ||
* Generate base vars for Wordnik's API | ||
* @constructs | ||
* @param {string} base | ||
* @param {string} key | ||
* @param {string} version | ||
*/ | ||
this.base = 'https://api.wordnik.com/' | ||
this.key = getKey() | ||
this.version = getVersion() | ||
} | ||
|
||
/** | ||
* @param {string} word | ||
* @param {string} target | ||
* @param {array} options | ||
* @returns {string} - url to fetch | ||
*/ | ||
word(word, target, options) { | ||
if (!word) word = 'hackable' | ||
if (!target) target = 'scrabbleScore' | ||
if (options) { | ||
this.key = '&' + this.key | ||
} else { | ||
this.key = '?' + this.key | ||
} | ||
|
||
return this.base + this.version + 'word.json/' + | ||
word + '/' + | ||
target + | ||
this.key | ||
} | ||
|
||
/** | ||
* @param {string} target | ||
* @param {*} options | ||
* @returns {string} - url to fetch | ||
*/ | ||
words(target, options) { | ||
if (!target) target = 'wordOfTheDay' | ||
if (options) { | ||
this.key = '&' + this.key | ||
} else { | ||
this.key = '?' + this.key | ||
} | ||
|
||
return this.base + this.version + 'words.json/' + | ||
target + | ||
this.key | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Module for Worknik's API | ||
* @module wordnik | ||
*/ | ||
|
||
export * from './main.js' | ||
export * from './word/mod.js' | ||
export * from './words/mod.js' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* [word] section of wordnik module | ||
* @module @wordnik/word | ||
* | ||
*/ | ||
|
||
export * from './scrabbleScore.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Wordnik } from '../main.js' | ||
|
||
const wordnik = new Wordnik() | ||
|
||
/** | ||
* Get the Scrabble score for a word | ||
* @param {string} word | ||
* @returns {integer} - score for the word | ||
*/ | ||
export async function scrabbleScore(word) { | ||
let response | ||
if (word) { | ||
response = await fetch(wordnik.word(word, 'scrabbleScore')) | ||
} else { | ||
response = await fetch(wordnik.word('hackable', 'scrabbleScore')) | ||
} | ||
|
||
if (response.status !== 200) { | ||
console.error('Error! Status:', response.statusText) | ||
return | ||
} | ||
|
||
const json = JSON.stringify(await response.json()) | ||
const data = JSON.parse(json) | ||
return data.value | ||
} | ||
|
||
/** | ||
* @example | ||
* ```js | ||
* import { scrabbleScore } from 'https://deno.land/x/wordnik/mod.js' | ||
* console.log(await scrabbleScore('cookie')) // returns cookie's score (12) | ||
* ``` | ||
*/ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"scripts": { | ||
"http:test": "./src/tests/vaildate.js", | ||
"clean": "rm -r ./static/out", | ||
"jsdoc": "npm run clean ; jsdoc ./src --configure ./jsdoc.json --destination ./static/out/" | ||
"jsdoc": "npm run clean ; jsdoc --configure ./jsdoc.json --destination ./static/out/" | ||
}, | ||
"keywords": [], | ||
"author": "ArkhamCookie <[email protected]> (https://theuntitledproject.dev)", | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.