{"id":18865823,"url":"https://github.com/proustibat/occurences","last_synced_at":"2025-04-14T14:23:37.322Z","repository":{"id":57313271,"uuid":"88203492","full_name":"proustibat/occurences","owner":"proustibat","description":"Calculate the number of occurrences of each word in a text. Words smaller than two letters will be ignored.","archived":false,"fork":false,"pushed_at":"2020-05-23T12:18:29.000Z","size":259,"stargazers_count":5,"open_issues_count":5,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T14:23:04.418Z","etag":null,"topics":["count","counter","coverage","javascript","letters","npm","npm-module","npm-package","occurences","occurrences","sonar-scanner","sonarcloud","sonarqube","statistics","stats","string","string-matching","strings","words","wordsearch"],"latest_commit_sha":null,"homepage":"https://proustibat.github.io/occurences/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/proustibat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-13T20:24:39.000Z","updated_at":"2024-11-05T10:18:19.000Z","dependencies_parsed_at":"2022-09-20T23:20:15.516Z","dependency_job_id":null,"html_url":"https://github.com/proustibat/occurences","commit_stats":null,"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proustibat%2Foccurences","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proustibat%2Foccurences/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proustibat%2Foccurences/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proustibat%2Foccurences/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/proustibat","download_url":"https://codeload.github.com/proustibat/occurences/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248895135,"owners_count":21179192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["count","counter","coverage","javascript","letters","npm","npm-module","npm-package","occurences","occurrences","sonar-scanner","sonarcloud","sonarqube","statistics","stats","string","string-matching","strings","words","wordsearch"],"created_at":"2024-11-08T05:04:42.662Z","updated_at":"2025-04-14T14:23:37.284Z","avatar_url":"https://github.com/proustibat.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Occurrences [![GitHub license](https://img.shields.io/github/license/proustibat/stats-text.svg)](https://github.com/proustibat/stats-text/blob/master/LICENSE.md)\n\nCalculate the number of occurrences of each word in a text. Get varisous stats: smallest, longest words, etc.\n\n\n\n| [![NPM](https://nodei.co/npm/occurences.png?compact=true)](https://www.npmjs.com/package/occurences) \u003c/br\u003e [![GitHub package version](https://img.shields.io/github/package-json/v/proustibat/occurences.svg)]() [![npm](https://img.shields.io/npm/v/occurences.svg)](https://www.npmjs.com/package/occurences) [![Npm downloads](https://img.shields.io/npm/dt/occurences.svg)](https://www.npmjs.com/package/occurences) | [![Maintenance](https://img.shields.io/maintenance/yes/2018.svg)](https://github.com/proustibat/occurences/commits/master) \u003c/br\u003e [![GitHub last commit](https://img.shields.io/github/last-commit/proustibat/occurences.svg)](https://github.com/proustibat/occurences/commits/master) \u003c/br\u003e [![Open issues](https://sonarcloud.io/api/badges/measure?key=proustibat_occurences\u0026metric=open_issues)](https://sonarcloud.io/component_measures?id=proustibat_occurences\u0026metric=open_issues) | [![Build Status](https://travis-ci.org/proustibat/occurences.svg?branch=master)](https://travis-ci.org/proustibat/occurences) \u003c/br\u003e [![Sonar quality gate](https://sonarcloud.io/api/badges/gate?key=proustibat_occurences)](https://sonarcloud.io/dashboard?id=proustibat_occurences) \u003c/br\u003e [![Code Climate](https://codeclimate.com/github/proustibat/occurences/badges/gpa.svg)](https://codeclimate.com/github/proustibat/occurences) \u003c/br\u003e [![Coverage Status](https://coveralls.io/repos/github/proustibat/occurences/badge.svg?branch=master)](https://coveralls.io/github/proustibat/occurences?branch=master) | [![Greenkeeper badge](https://badges.greenkeeper.io/proustibat/occurences.svg)](https://greenkeeper.io/) \u003c/br\u003e[![Dependencies Status](https://david-dm.org/proustibat/stats-text/status.svg)](https://david-dm.org/proustibat/stats-text) \u003c/br\u003e[![DevDependencies Status](https://david-dm.org/proustibat/stats-text/dev-status.svg)](https://david-dm.org/proustibat/stats-text?type=dev) |\n| --- | :--- | :---- | :----\n\n-------------\n\n## Installation\n`npm i -S occurences`\n\n## Usage\n\n### Javascript\n\n```js\nconst Occurrences = require('occurences');\nlet occ = new Occurrences(data, [options])\n```\nWhere data is a string. Options object isn't required.\n\nRunning example on Runkit.com: [https://runkit.com/proustibat/occurences-example-request](https://runkit.com/proustibat/occurences-example-request)\n\n\n### Typescript\nWanna use it with Angular 2? For example in an Ionic application. Import as follows:\n\n```typescript\nimport * as Occurences from 'Occurences';\n```\n\nNote that `stats` of an instance is an object. So to list the words in an ionic template with `*ngFor`, proceed as follows to transform it in an array: \n\n*Typescript file:* \n\n```typescript\n    this.textOccurrences = new Occurences(this.text);\n    this.statsArray = Object.keys(this.textOccurrences.stats).map( key =\u003e {\n        return { word: key, number: this.textOccurrences.stats[key] };\n    });\n```\n*HTML :*\n```html\n\u003ctable\u003e\n    \u003ctr *ngFor=\"let item of statsArray\"\u003e\n        \u003ctd\u003e{{ item.word }}\u003c/td\u003e\n        \u003ctd\u003e{{ item.number }}\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n```\n\n\n### Options \n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\nsensitiveCase | Boolean | false | If defined to true, counts as 2 different words same word with uppercases\nignored | String or Array | - | One or several words to ignore when counting occurrences\nbiggerThan | int | 2 | Considers only words larger than this number of letters\n\n\n## Properties \n\nProperty | Type  | Description\n-------- | ----  | -----------\nstats | Object | Each words occurrences: word as key, occurence number as value (read-only)\nmeta | Object | Global stats about the data: total number of words, number of different words, total number of characters with spaces (`charsWS`) or no (`charsNS`)  Returns an object as follows: `{totalWords:int, differentWords:int, charsWS:int, charsNS:int}`\nlessUsed | Array | The less used word of the data (read-only)\nmostUsed | Array | The most used word of the data (read-only)\nsmallest | Array | The smallest used word (read-only)\nlongest | Array | The longest used word (read-only)\noptions | Object | Settings of the instance (read-only)\n\n\n## Methods \n\nProperty | Parameters | Default | Description\n-------- | ---------- | ------- | -----------\ngetSorted | String: '*desc*', '*asc*' | 'desc' | Returns an array with objects sorted by order descendant or ascendant, each index of the array is an object as follows : `{word:'three', number: '3'}`\n\n## Examples\n\n### Example with latin alphabet\n\n#### Simple stats\n```\nconst Occurrences = require('occurences'); // note the lib is named with only one R\nconst latinText = \"Not connected to power. Power is it good or bad. What is power? Dunno what power is but I know what it's not.\";\nlet occurrencesLatin = new Occurrences(latinText);\nconsole.log(occurrencesLatin.stats);\n```\n**Output:** \n```\n{ \n    not: 2,\n    connected: 1,\n    power: 4,\n    good: 1,\n    bad: 1,\n    what: 3,\n    dunno: 1,\n    but: 1,\n    know: 1,\n    'it\\'s': 1 \n}\n```\n\n### Other properties\n\n```\nconsole.log(\"longest: \", occurrencesLatin.longest);\nconsole.log(\"smallest: \", occurrencesLatin.smallest);\nconsole.log(\"lessUsed: \", occurrencesLatin.lessUsed);\nconsole.log(\"mostUsed: \", occurrencesLatin.mostUsed);\nconsole.log(\"getSorted: \", occurrencesLatin.getSorted());\n```\n**Output:** \n```\nlongest:  ['connected']\nsmallest:  [ 'not', 'bad', 'but' ]\nlessUsed:  [ 'connected', 'good', 'bad', 'dunno', 'but', 'know', 'it\\'s' ]\nmostUsed:  ['power']\ngetSorted:  [ { value: 'power', number: 4 },\n  { value: 'what', number: 3 },\n  { value: 'not', number: 2 },\n  { value: 'connected', number: 1 },\n  { value: 'good', number: 1 },\n  { value: 'bad', number: 1 },\n  { value: 'dunno', number: 1 },\n  { value: 'but', number: 1 },\n  { value: 'know', number: 1 },\n  { value: 'it\\'s', number: 1 } ]\n```\n\n### Example with hebrew alphabet\n\n```\nconst Occurrences = require('occurences'); // note the lib is named with only one R\nconst hebrewText = \"שלום! חג פסח שמח ו שבת שלום לכולם!\";\nlet occurrencesHebrew = new Occurrences(hebrewText);\nconsole.log(occurrencesHebrew.stats);\n\n```\n**Output:** \n```\n{ \n\t'שלום': 2, \n\t'פסח': 1, \n\t'שמח': 1, \n\t'שבת': 1, \n\t'לכולם': 1 \n}\n```\n*Note that text editor don't outputs from left to right but the object is ok in real life*\n\n\n### Example with async data\n\n```\nconst Occurrences = require('occurences');  // note the lib is named with only one R\nconst request = require('request');         // note you have to install request lib\nconst url = \"http://faker.hook.io/?property=lorem.sentences\";\nrequest({\n    url: url,\n    json: true\n}, function (error, response, data) {\n    if (!error \u0026\u0026 response.statusCode === 200) {\n        let myResult = new Occurrences(data);\n        console.log(myResult.stats);\n    }\n    else {\n        console.log(\"It seems an error occured when requesting \", url);\n    }\n});\n\n```\n\n**Output:** \n```\n{ \n    nobis: 1,\n    quam: 1,\n    sapiente: 1,\n    fugiat: 1,\n    cumque: 2,\n    nisi: 1,\n    voluptatem: 1,\n    sint: 1,\n    quibusdam: 1,\n    impedit: 1,\n    modi: 2,\n    expedita: 1,\n    deserunt: 1,\n    non: 1 \n}\n```\n\n## Tests\n`npm test`\n\n## Coverage\n`npm run cover`\n\n## Continuous Code Quality\nI use [Sonarqube](https://www.sonarqube.org/) on [Sonarcloud.io](https://sonarcloud.io/) to maintain clean code.\nPublic dashboard is here: [https://sonarcloud.io/dashboard?id=proustibat_occurences](https://sonarcloud.io/dashboard?id=proustibat_occurences)\n\n### Some results:\n[![Comments (%)](https://sonarcloud.io/api/badges/measure?key=proustibat_occurences\u0026metric=comment_lines_density)](https://sonarcloud.io/component_measures?id=proustibat_occurences\u0026metric=comment_lines_density)\n[![Open issues](https://sonarcloud.io/api/badges/measure?key=proustibat_occurences\u0026metric=open_issues)](https://sonarcloud.io/component_measures?id=proustibat_occurences\u0026metric=open_issues)\n[![Code smells](https://sonarcloud.io/api/badges/measure?key=proustibat_occurences\u0026metric=code_smells)](https://sonarcloud.io/component_measures?id=proustibat_occurences\u0026metric=code_smells)\n[![Technical debt](https://sonarcloud.io/api/badges/measure?key=proustibat_occurences\u0026metric=sqale_index)](https://sonarcloud.io/component_measures?id=proustibat_occurences\u0026metric=sqale_index)\n[![Bugs](https://sonarcloud.io/api/badges/measure?key=proustibat_occurences\u0026metric=bugs)](https://sonarcloud.io/component_measures?id=proustibat_occurences\u0026metric=bugs)\n[![Reliability remediation effort](https://sonarcloud.io/api/badges/measure?key=proustibat_occurences\u0026metric=reliability_remediation_effort)](https://sonarcloud.io/component_measures?id=proustibat_occurences\u0026metric=reliability_remediation_effort)\n[![Coverage](https://sonarcloud.io/api/badges/measure?key=proustibat_occurences\u0026metric=coverage)](https://sonarcloud.io/component_measures?id=proustibat_occurences\u0026metric=coverage)\n\n### Using Sonar Scanner\nBe sure you have downloaded and installed the [Sonarqube Scanner](https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner).\nYou need to add sonar-project.properties to the root of the project as folllows:\n\n```\nsonar.projectName=Occurences\nsonar.projectKey=proustibat_occurences\nsonar.host.url=https://sonarcloud.io\nsonar.organization=proustibat-github\nsonar.login=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nsonar.sources=.\nsonar.exclusions=node_modules/**/*,coverage/**/*,example.js,test/**/*\nsonar.javascript.lcov.reportPath=coverage/lcov.info\nsonar.java.source=1.8\nsonar.java.binaries=.\n\n```\n\nAnd then run sonar scanner as follows:\n\n```\nsonar-scanner -X -Dsonar.projectVersion=x.x.x\n```\n\nMore information on [Sonarcloud.io](https://about.sonarcloud.io/get-started/)\n\n\n## Contributing\n\n- Issue Tracker: [https://github.com/proustibat/occurences/issues](https://github.com/proustibat/occurences/issues)\n- Source Code: [https://github.com/proustibat/occurences](https://github.com/proustibat/occurences)\n- Pull Requests: [https://github.com/proustibat/occurences/pulls](https://github.com/proustibat/occurences/pulls)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproustibat%2Foccurences","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fproustibat%2Foccurences","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproustibat%2Foccurences/lists"}