Socket
Socket
Sign inDemoInstall

syllable

Package Overview
Dependencies
3
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.0 to 5.0.0

index.d.ts

46

cli.js
#!/usr/bin/env node
'use strict'
import fs from 'fs'
import {URL} from 'url'
import {syllable} from './index.js'
var pack = require('./package.json')
var syllable = require('.')
/** @type {Object.<string, unknown>} */
var pack = JSON.parse(
String(fs.readFileSync(new URL('./package.json', import.meta.url)))
)

@@ -11,5 +15,5 @@ var argv = process.argv.slice(2)

if (argv.indexOf('--help') !== -1 || argv.indexOf('-h') !== -1) {
if (argv.includes('--help') || argv.includes('-h')) {
console.log(help())
} else if (argv.indexOf('--version') !== -1 || argv.indexOf('-v') !== -1) {
} else if (argv.includes('--version') || argv.includes('-v')) {
console.log(pack.version)

@@ -24,15 +28,31 @@ } else if (argv.length === 0) {

/**
* @param {string} value
*/
function getSyllables(value) {
value = value.split(/\s+/g).map(trim).filter(Boolean)
var values = value
.split(/\s+/g)
.map((/** @type {string} */ d) => d.trim())
.filter(Boolean)
if (value.length === 0) {
if (values.length === 0) {
process.stderr.write(help())
process.exit(1)
} else {
console.log(syllables(value))
console.log(syllables(values))
}
}
/**
* @param {Array.<string>} values
*/
function syllables(values) {
return values.map(syllable).reduce(sum)
var sum = 0
var index = -1
while (++index < values.length) {
sum += syllable(values[index])
}
return sum
}

@@ -66,9 +86,1 @@

}
function sum(a, b) {
return a + b
}
function trim(d) {
return d.trim()
}

@@ -1,9 +0,6 @@

'use strict'
import pluralize from 'pluralize'
// @ts-ignore remove when typed.
import normalize from 'normalize-strings'
import {problematic} from './problematic.js'
var pluralize = require('pluralize')
var normalize = require('normalize-strings')
var problematic = require('./problematic.json')
module.exports = syllables
var own = {}.hasOwnProperty

@@ -231,36 +228,44 @@

// Expression to split on word boundaries.
var SPLIT = /\b/g
// Expression to merge elision.
var APOSTROPHE = /['’]/g
// Expression to remove non-alphabetic characters from a given value.
var EXPRESSION_NONALPHABETIC = /[^a-z]/g
// Wrapper to support multiple word-parts (GH-11).
function syllables(value) {
/**
* Syllable count
*
* @param {string} value
* @returns {number}
*/
export function syllable(value) {
var values = normalize(String(value))
.toLowerCase()
.replace(APOSTROPHE, '')
.split(SPLIT)
var length = values.length
// Remove apostrophes.
.replace(/['’]/g, '')
// Split on word boundaries.
.split(/\b/g)
var index = -1
var total = 0
var sum = 0
while (++index < length) {
total += syllable(values[index].replace(EXPRESSION_NONALPHABETIC, ''))
while (++index < values.length) {
// Remove non-alphabetic characters from a given value.
sum += one(values[index].replace(/[^a-z]/g, ''))
}
return total
return sum
}
// Get syllables in a given value.
function syllable(value) {
/**
* Get syllables in a given value.
*
* @param {string} value
* @returns {number}
*/
function one(value) {
var count = 0
/** @type {number} */
var index
var length
/** @type {string} */
var singular
/** @type {Array.<string>} */
var parts
/** @type {ReturnType.<returnFactory>} */
var addOne
/** @type {ReturnType.<returnFactory>} */
var subtractOne

@@ -301,5 +306,4 @@

index = -1
length = parts.length
while (++index < length) {
while (++index < parts.length) {
if (parts[index] !== '') {

@@ -327,6 +331,13 @@ count++

// Define scoped counters, to be used in `String#replace()` calls.
// The scoped counter removes the matched value from the input.
/**
* Define scoped counters, to be used in `String#replace()` calls.
* The scoped counter removes the matched value from the input.
*
* @param {number} addition
*/
function countFactory(addition) {
return counter
/**
* @returns {string}
*/
function counter() {

@@ -338,6 +349,13 @@ count += addition

// Define scoped counters, to be used in `String#replace()` calls.
// The scoped counter does not remove the matched value from the input.
/**
* This scoped counter does not remove the matched value from the input.
*
* @param {number} addition
*/
function returnFactory(addition) {
return returner
/**
* @param {string} $0
* @returns {string}
*/
function returner($0) {

@@ -344,0 +362,0 @@ count += addition

{
"name": "syllable",
"version": "4.1.0",
"version": "5.0.0",
"description": "Count syllables in English words",

@@ -25,9 +25,15 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"bin": "cli.js",
"main": "index.js",
"types": "index.d.ts",
"files": [
"problematic.json",
"index.js",
"cli.js"
"cli.js",
"problematic.js",
"index.d.ts",
"index.js"
],
"bin": "cli.js",
"dependencies": {
"@types/pluralize": "^0.0.29",
"normalize-strings": "^1.1.0",

@@ -37,26 +43,21 @@ "pluralize": "^8.0.0"

"devDependencies": {
"browserify": "^16.0.0",
"nyc": "^15.0.0",
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^8.0.0",
"remark-preset-wooorm": "^7.0.0",
"tape": "^4.0.0",
"tinyify": "^2.0.0",
"xo": "^0.29.0"
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.38.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"build-bundle": "browserify . -s syllable > syllable.js",
"build-mangle": "browserify . -s syllable -p tinyify > syllable.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test": "npm run format && npm run build && npm run test-coverage"
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test/index.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
"test": "npm run build && npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {

@@ -72,10 +73,7 @@ "tabWidth": 2,

"prettier": true,
"esnext": false,
"rules": {
"unicorn/prefer-includes": "off",
"guard-for-in": "off"
},
"ignores": [
"syllable.js"
]
"import/no-mutable-exports": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
},

@@ -86,3 +84,8 @@ "remarkConfig": {

]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

@@ -12,2 +12,5 @@ # syllable

This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
instead of `require`d.
[npm][]:

@@ -21,4 +24,7 @@

This package exports the following identifiers: `syllable`.
There is no default export.
```js
var syllable = require('syllable')
import {syllable} from 'syllable'

@@ -115,5 +121,5 @@ syllable('syllable') // 3

[build-badge]: https://img.shields.io/travis/words/syllable.svg
[build-badge]: https://github.com/words/syllable/workflows/main/badge.svg
[build]: https://travis-ci.org/words/syllable
[build]: https://github.com/words/syllable/actions

@@ -120,0 +126,0 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/words/syllable.svg

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc