New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

classify-poetry

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classify-poetry - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

.github/workflows/ci.yml

15

classifiers/abc.js

@@ -1,7 +0,10 @@

"use strict";
import { parseLines } from "../utils/parseLines.js";
var parseLines = require("../utils/parseLines");
function abc(str) {
var char = 97; // 'a'
/**
*
* @param {string} str
* @returns {boolean}
*/
export function abc(str) {
let char = 97; // 'a'
return (

@@ -15,3 +18,1 @@ parseLines(str)

}
module.exports = abc;

@@ -1,6 +0,7 @@

const test = require("ava");
const abc = require("./abc");
import { test } from "uvu";
import { is } from "uvu/assert";
import { abc } from "./abc.js";
test("abc poem", (t) => {
t.true(
test("abc poem", () => {
is(
abc(`

@@ -10,8 +11,9 @@ a poem

case
`)
`),
true
);
});
test("not abc poem", (t) => {
t.false(
test("not abc poem", () => {
is(
abc(`

@@ -21,4 +23,7 @@ random

for testing
`)
`),
false
);
});
test.run();

@@ -1,9 +0,12 @@

"use strict";
import { lookupSounds } from "../utils/lookupSounds.js";
import { parseLines } from "../utils/parseLines.js";
var lookupSounds = require("../utils/lookupSounds");
var parseLines = require("../utils/parseLines");
/**
*
* @param {string} str
* @returns {boolean}
*/
export function couplet(str) {
const lines = parseLines(str);
function haiku(str) {
var lines = parseLines(str);
// odd number of lines

@@ -14,3 +17,3 @@ if (lines.length % 2 === 1) {

var sounds = lookupSounds(lines);
const sounds = lookupSounds(lines);

@@ -27,3 +30,1 @@ return sounds.every(function (sound, index) {

}
module.exports = haiku;

@@ -1,24 +0,27 @@

const test = require("ava");
const couplet = require("./couplet");
import { test } from "uvu";
import { is } from "uvu/assert";
import { couplet } from "./couplet.js";
test("couple poem 1", (t) => {
t.true(
test("couple poem 1", () => {
is(
couplet(`
True wit is nature to advantage dressed;
What oft was thought, but ne'er so well expressed.."
`) // Alexander Pope
`), // Alexander Pope
true
);
});
test("couple poem 2", (t) => {
t.true(
test("couple poem 2", () => {
is(
couplet(`
Whether or not we find what we are seeking
Is idle, biologically speaking.
`) // Edna St. Vincent Millay
`), // Edna St. Vincent Millay
true
);
});
test("not couple poem", (t) => {
t.false(
test("not couple poem", () => {
is(
couplet(`

@@ -28,4 +31,7 @@ random

for testing
`)
`),
false
);
});
test.run();

@@ -1,9 +0,12 @@

"use strict";
import { lookupSyllables } from "../utils/lookupSyllables.js";
import { parseLines } from "../utils/parseLines.js";
var lookupSyllables = require("../utils/lookupSyllables");
var parseLines = require("../utils/parseLines");
/**
*
* @param {string} str
* @returns {boolean}
*/
export function haiku(str) {
const lines = parseLines(str);
function haiku(str) {
var lines = parseLines(str);
if (lines.length !== 3) {

@@ -13,3 +16,3 @@ return false;

var syllables = lookupSyllables(lines);
const syllables = lookupSyllables(lines);

@@ -19,3 +22,1 @@ // 5 7 5

}
module.exports = haiku;

@@ -1,6 +0,7 @@

const test = require("ava");
const haiku = require("./haiku");
import { test } from "uvu";
import { is } from "uvu/assert";
import { haiku } from "./haiku.js";
test("haiku poem", (t) => {
t.true(
test("haiku poem", () => {
is(
haiku(`

@@ -10,8 +11,9 @@ detect a haiku

thanks algorithm
`)
`),
true
);
});
test("not haiku poem", (t) => {
t.false(
test("not haiku poem", () => {
is(
haiku(`

@@ -21,4 +23,7 @@ random

for testing
`)
`),
false
);
});
test.run();

@@ -1,9 +0,12 @@

"use strict";
import { lookupSounds } from "../utils/lookupSounds.js";
import { parseLines } from "../utils/parseLines.js";
var lookupSounds = require("../utils/lookupSounds");
var parseLines = require("../utils/parseLines");
/**
*
* @param {string} str
* @returns {boolean}
*/
export function limerick(str) {
const lines = parseLines(str);
function terzaRima(str) {
var lines = parseLines(str);
if (lines.length !== 5) {

@@ -13,3 +16,3 @@ return false;

var sounds = lookupSounds(lines);
const sounds = lookupSounds(lines);

@@ -23,3 +26,1 @@ // AABBA

}
module.exports = terzaRima;

@@ -1,6 +0,7 @@

const test = require("ava");
const limerick = require("./limerick");
import { test } from "uvu";
import { is } from "uvu/assert";
import { limerick } from "./limerick.js";
test("limerick poem", (t) => {
t.true(
test("limerick poem", () => {
is(
limerick(`

@@ -12,8 +13,9 @@ The limerick packs laughs anatomical

And the clean ones so seldom are comical.
`) // unknown origin
`), // unknown origin
true
);
});
test("not limerick poem", (t) => {
t.false(
test("not limerick poem", () => {
is(
limerick(`

@@ -23,4 +25,7 @@ random

for testing
`)
`),
false
);
});
test.run();

@@ -1,9 +0,12 @@

"use strict";
import { lookupSounds } from "../utils/lookupSounds.js";
import { parseLines } from "../utils/parseLines.js";
var lookupSounds = require("../utils/lookupSounds");
var parseLines = require("../utils/parseLines");
/**
*
* @param {string} str
* @returns {boolean}
*/
export function quatrain(str) {
const lines = parseLines(str);
function sonnet(str) {
var lines = parseLines(str);
if (lines.length !== 4) {

@@ -14,3 +17,3 @@ return false;

// A and B can appear in any order
var sounds = lookupSounds(lines).sort();
const sounds = lookupSounds(lines).sort();

@@ -23,3 +26,1 @@ return (

}
module.exports = sonnet;

@@ -1,6 +0,7 @@

const test = require("ava");
const quatrain = require("./quatrain");
import { test } from "uvu";
import { is } from "uvu/assert";
import { quatrain } from "./quatrain.js";
test("quatrain poem 1", (t) => {
t.true(
test("quatrain poem 1", () => {
is(
quatrain(`

@@ -11,8 +12,9 @@ The curfew tolls the knell of parting day,

And leaves the world to darkness and to me.
`) // Elegy Written in a Country Churchyard, by Thomas Gray
`), // Elegy Written in a Country Churchyard, by Thomas Gray
true
);
});
test("quatrain poem 2", (t) => {
t.true(
test("quatrain poem 2", () => {
is(
quatrain(`

@@ -23,8 +25,9 @@ Come, fill the Cup, and in the fire of Spring

To flutter—and the Bird is on the Wing
`) // Rubaiyat of Omar Khayyam, by Edward FitzGerald
`), // Rubaiyat of Omar Khayyam, by Edward FitzGerald
true
);
});
test("not quatrain poem", (t) => {
t.false(
test("not quatrain poem", () => {
is(
quatrain(`

@@ -34,4 +37,7 @@ random

for testing
`)
`),
false
);
});
test.run();

@@ -1,9 +0,12 @@

"use strict";
import { lookupSounds } from "../utils/lookupSounds.js";
import { parseLines } from "../utils/parseLines.js";
var lookupSounds = require("../utils/lookupSounds");
var parseLines = require("../utils/parseLines");
/**
*
* @param {string} str
* @returns {boolean}
*/
export function sonnet(str) {
const lines = parseLines(str);
function sonnet(str) {
var lines = parseLines(str);
if (lines.length !== 14) {

@@ -13,3 +16,3 @@ return false;

var sounds = lookupSounds(lines);
const sounds = lookupSounds(lines);

@@ -31,3 +34,1 @@ // ABBA ABBA CDE CDE

}
module.exports = sonnet;

@@ -1,6 +0,7 @@

const test = require("ava");
const sonnet = require("./sonnet");
import { test } from "uvu";
import { is } from "uvu/assert";
import { sonnet } from "./sonnet.js";
test("sonnet poem", (t) => {
t.true(
test("sonnet poem", () => {
is(
sonnet(`

@@ -21,8 +22,9 @@ When I consider how my light is spent

They also serve who only stand and wait."
`) // On His Blindness, by Milton
`), // On His Blindness, by Milton
true
);
});
test("not sonnet poem", (t) => {
t.false(
test("not sonnet poem", () => {
is(
sonnet(`

@@ -32,4 +34,7 @@ random

for testing
`)
`),
false
);
});
test.run();

@@ -1,9 +0,12 @@

"use strict";
import { parseLines } from "../utils/parseLines.js";
import { lookupSyllables } from "../utils/lookupSyllables.js";
var lookupSyllables = require("../utils/lookupSyllables");
var parseLines = require("../utils/parseLines");
/**
*
* @param {string} str
* @returns {boolean}
*/
export function tanka(str) {
const lines = parseLines(str);
function tanka(str) {
var lines = parseLines(str);
if (lines.length !== 5) {

@@ -13,3 +16,3 @@ return false;

var syllables = lookupSyllables(lines);
const syllables = lookupSyllables(lines);

@@ -25,3 +28,1 @@ // 5 7 5 7 7

}
module.exports = tanka;

@@ -1,6 +0,7 @@

const test = require("ava");
const tanka = require("./tanka");
import { test } from "uvu";
import { is } from "uvu/assert";
import { tanka } from "./tanka.js";
test("taka poem", (t) => {
t.true(
test("taka poem", () => {
is(
tanka(`

@@ -12,8 +13,9 @@ detect a tanka

another tanka poem found
`)
`),
true
);
});
test("not haiku poem", (t) => {
t.false(
test("not haiku poem", () => {
is(
tanka(`

@@ -23,4 +25,7 @@ random

for testing
`)
`),
false
);
});
test.run();

@@ -1,9 +0,12 @@

"use strict";
import { lookupSounds } from "../utils/lookupSounds.js";
import { parseLines } from "../utils/parseLines.js";
var lookupSounds = require("../utils/lookupSounds");
var parseLines = require("../utils/parseLines");
/**
*
* @param {string} str
* @returns {boolean}
*/
export function terzaRima(str) {
const lines = parseLines(str);
function terzaRima(str) {
var lines = parseLines(str);
if (lines.length < 12) {

@@ -13,3 +16,3 @@ return false;

var sounds = lookupSounds(lines);
const sounds = lookupSounds(lines);

@@ -27,3 +30,1 @@ // ABA BCB CDC DED

}
module.exports = terzaRima;

@@ -1,6 +0,7 @@

const test = require("ava");
const terzaRima = require("./terzaRima");
import { test } from "uvu";
import { is } from "uvu/assert";
import { terzaRima } from "./terzaRima.js";
test("terza rima poem", (t) => {
t.true(
test("terza rima poem", () => {
is(
terzaRima(`

@@ -25,8 +26,9 @@ I have been one acquainted with the night.

I have been one acquainted with the night.
`) // Acquainted with the Night, by Robert Frost
`), // Acquainted with the Night, by Robert Frost
true
);
});
test("not terza rima poem", (t) => {
t.false(
test("not terza rima poem", () => {
is(
terzaRima(`

@@ -36,4 +38,7 @@ random

for testing
`)
`),
false
);
});
test.run();

@@ -1,31 +0,32 @@

var abc = require("./classifiers/abc");
var couplet = require("./classifiers/couplet");
var haiku = require("./classifiers/haiku");
var limerick = require("./classifiers/limerick");
var quatrain = require("./classifiers/quatrain");
var sonnet = require("./classifiers/sonnet");
var tanka = require("./classifiers/tanka");
var terzaRima = require("./classifiers/terzaRima");
import { abc } from "./classifiers/abc";
import { couplet } from "./classifiers/couplet";
import { haiku } from "./classifiers/haiku";
import { limerick } from "./classifiers/limerick";
import { quatrain } from "./classifiers/quatrain";
import { sonnet } from "./classifiers/sonnet";
import { tanka } from "./classifiers/tanka";
import { terzaRima } from "./classifiers/terzaRima";
var all = [abc, couplet, haiku, limerick, quatrain, sonnet, tanka, terzaRima];
const all = [abc, couplet, haiku, limerick, quatrain, sonnet, tanka, terzaRima];
/**
*
* @param {string} str
* @returns {string[]}
*/
function classifyPoetry(str) {
return all
.filter(function (type) {
return type(str);
})
.map(function (type) {
return type.name;
});
return all.filter((type) => type(str)).map((type) => type.name);
}
exports.all = all;
exports.classifyPoetry = classifyPoetry;
exports.abc = abc;
exports.couplet = couplet;
exports.haiku = haiku;
exports.limerick = limerick;
exports.quatrain = quatrain;
exports.sonnet = sonnet;
exports.tanka = tanka;
exports.terzaRima = terzaRima;
export {
classifyPoetry,
all,
abc,
couplet,
haiku,
limerick,
quatrain,
sonnet,
tanka,
terzaRima,
};
{
"name": "classify-poetry",
"version": "0.2.0",
"version": "1.0.0",
"description": "recognize type poetry in a given text excerpt",
"type": "module",
"main": "index.js",
"scripts": {
"test": "ava",
"format": "prettier --write '*.{js,md}' 'classifiers/*.js'"
"test": "rimraf \"*.d.ts\" \"classifiers/*.d.ts\" \"utils/*.d.ts\" && uvu classifiers && tsc && type-coverage",
"format": "prettier --write \"*.{js,md}\" \"classifiers/*.js\"",
"prepublishOnly": "npm run test"
},

@@ -35,9 +37,17 @@ "repository": {

"devDependencies": {
"ava": "^3.0.0",
"prettier": "^2.0.3"
"prettier": "~2.3.0",
"rimraf": "^3.0.2",
"type-coverage": "^2.0.0",
"typescript": "~4.3.0",
"uvu": "^0.5.0"
},
"dependencies": {
"cmu-pronouncing-dictionary": "^2.0.0",
"syllable": "^4.0.0"
"cmu-pronouncing-dictionary": "^3.0.0",
"syllable": "^5.0.0"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}
# classify-poetry
[![NPM Version](https://img.shields.io/npm/v/classify-poetry.svg)](https://www.npmjs.com/package/classify-poetry)
[![Build Status](https://travis-ci.com/ChristianMurphy/classify-poetry.svg?branch=master)](https://travis-ci.com/ChristianMurphy/classify-poetry)
[![Build status](https://github.com/ChristianMurphy/classify-poetry/workflows/CI/badge.svg?branch=main)](https://github.com/ChristianMurphy/classify-poetry/actions)

@@ -10,2 +10,5 @@ > recognize the type of poetry in a given excerpt

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
```sh

@@ -20,4 +23,4 @@ npm install classify-poetry

```js
var classifyPoetry = require("classify-poetry").classifyPoetry;
var types = classifyPoetry(
import { classifyPoetry } from "classify-poetry";
const types = classifyPoetry(
"detect a haiku \n pleased to do, says algorithm \n thanks algorithm"

@@ -33,3 +36,3 @@ );

```js
var abc = require("classify-poetry").abc;
import { abc } from "classify-poetry";
abc(sampleText); // => true or false

@@ -43,3 +46,3 @@ ```

```js
var couplet = require("classify-poetry").couplet;
import { couplet } from "classify-poetry";
couplet(sampleText); // => true or false

@@ -53,3 +56,3 @@ ```

```js
var haiku = require("classify-poetry").haiku;
import { haiku } from "classify-poetry";
haiku(sampleText); // => true or false

@@ -63,3 +66,3 @@ ```

```js
var limerick = require("classify-poetry").limerick;
import { limerick } from "classify-poetry";
limerick(sampleText); // => true or false

@@ -73,3 +76,3 @@ ```

```js
var quatrain = require("classify-poetry").quatrain;
import { quatrain } from "classify-poetry";
quatrain(sampleText); // => true or false

@@ -83,3 +86,3 @@ ```

```js
var sonnet = require("classify-poetry").sonnet;
import { sonnet } from "classify-poetry";
sonnet(sampleText); // => true or false

@@ -93,3 +96,3 @@ ```

```js
var tanka = require("classify-poetry").tanka;
import { tanka } from "classify-poetry";
tanka(sampleText); // => true or false

@@ -103,3 +106,3 @@ ```

```js
var terzaRima = require("classify-poetry").terzaRima;
import { terzaRima } from "classify-poetry";
terzaRima(sampleText); // => true or false

@@ -106,0 +109,0 @@ ```

@@ -1,4 +0,9 @@

var words = require("cmu-pronouncing-dictionary");
import {dictionary} from "cmu-pronouncing-dictionary"
module.exports = function (lines) {
/**
*
* @param {string[]} lines
* @returns {string[]}
*/
export function lookupSounds (lines) {
return lines

@@ -9,9 +14,9 @@ .map(function (line) {

})
.map(function (wordandPuncutation) {
.map(function (wordAndPunctuation) {
// just the word
return wordandPuncutation.match(/[\w]+/)[0];
return wordAndPunctuation.match(/[\w]+/)[0];
})
.map(function (word) {
// lookup in cmu pronunciation dictionary
return words[word.toLowerCase()];
return dictionary[word.toLowerCase()];
})

@@ -18,0 +23,0 @@ .map(function (sounds) {

@@ -1,4 +0,9 @@

var syllable = require("syllable");
import {syllable} from "syllable"
module.exports = function (lines) {
/**
*
* @param {string[]} lines
* @returns {number[]}
*/
export function lookupSyllables (lines) {
return lines.map(function (line) {

@@ -5,0 +10,0 @@ return syllable(line);

@@ -1,2 +0,7 @@

module.exports = function (str) {
/**
*
* @param {string} str
* @returns {string[]}
*/
export function parseLines (str) {
return str

@@ -3,0 +8,0 @@ .trim()

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