Skip to content

Commit

Permalink
Merge pull request #14 from mrodrig/tsify
Browse files Browse the repository at this point in the history
Migrate to TypeScript
  • Loading branch information
mrodrig authored Apr 23, 2023
2 parents 0da2034 + fe950ea commit 4e390b6
Show file tree
Hide file tree
Showing 21 changed files with 5,118 additions and 888 deletions.
52 changes: 52 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module.exports = {
root: true,
env: {
es2022: true,
node: true,
mocha: true,
},
parserOptions: {
ecmaVersion: 13,
project: ['tsconfig.json'],
sourceType: 'module',
tsconfigRootDir: __dirname,
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
ignorePatterns: [
'/lib/**/*', // Ignore built files.
],
plugins: [
'@typescript-eslint',
'import',
],
rules: {
// Basic ES6
indent: [
'error', 4, { // use 4 spaces for indents
'SwitchCase': 1, // indent case within switch
}
],
'linebreak-style': 0, // mixed environment let git config enforce line endings
quotes: ['error', 'single'],
semi: ['error', 'always'],
'no-var': 'error',
'no-console': 0, // allow use of console.log,
'arrow-body-style': [0, 'always'],
'max-len': 0,
'camelcase': 1,
'import/no-unresolved': [
'error', {
// https://github.com/firebase/firebase-admin-node/discussions/1359
ignore: ['^firebase-admin/.+'],
},
],
'@typescript-eslint/consistent-type-definitions': 'warn'
},
};
42 changes: 42 additions & 0 deletions .github/workflows/automated-tests-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Automated Node Version Tests

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
node: [16, 18, 19]

steps:
- uses: actions/checkout@v3
- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Install NPM Modules
run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: |
npm run coverage
- name: Coveralls Parallel
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: node-${{ runner.os }}-${{ matrix.node }}
parallel: true

coveralls-finished:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
33 changes: 7 additions & 26 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
# Created by .gitignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
.nyc_output

# Dependency directory
# Commenting this out is preferred by some people, see
# https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

# Users Environment Variables
.lock-wscript

# Users Environment Configurations
.idea

test/CSV/*
# Debug logs
npm-debug.log

# Built JavaScript files
lib
30 changes: 26 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
test/
.git*
# Debug Logs
npm-debug.log
.travis.yml

# Uncompiled Source Files
src
test

# Node Modules
node_modules/
node_modules/*

# Configuration Files
.eslintrc*
tsconfig*

# Test/Coverage Files
coverage/
coverage/*
demo
.nycrc
.nyc_output
.nyc_output/*
.coveralls.yml
lib/test

# Github Configuration Files
_config.yml
.git*

# Extra documentation files
upgrade_guides/*

demo*
16 changes: 16 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"check-coverage": true,
"all": true,
"include": [
"src/**/!(*.test.*).[tj]s?(x)"
],
"exclude": [
"test/**/*.*"
],
"reporter": [
"lcov",
"text-summary",
"text"
],
"report-dir": "coverage"
}
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

101 changes: 38 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

**This node module will take an array of tags and counts and generate a Tag/Word Cloud.**

[![Dependencies](https://img.shields.io/david/mrodrig/tag-cloud.svg?style=flat-square)](https://www.npmjs.org/package/tag-cloud)
[![Build Status](https://travis-ci.org/mrodrig/tag-cloud.svg?branch=master)](https://travis-ci.org/mrodrig/tag-cloud)
[![Downloads](http://img.shields.io/npm/dm/tag-cloud.svg)](https://www.npmjs.org/package/tag-cloud)
[![NPM version](https://img.shields.io/npm/v/tag-cloud.svg)](https://www.npmjs.org/package/tag-cloud)
[![Maintainability](https://api.codeclimate.com/v1/badges/7f915482db8fb7650731/maintainability)](https://codeclimate.com/github/mrodrig/tag-cloud/maintainability)
[![Known Vulnerabilities](https://snyk.io/test/npm/tag-cloud/badge.svg)](https://snyk.io/test/npm/tag-cloud)
[![Typings](https://img.shields.io/npm/types/tag-cloud)](https://www.npmjs.org/package/tag-cloud)
[![Downloads](https://img.shields.io/npm/dm/tag-cloud.svg)](https://www.npmjs.org/package/tag-cloud)
[![Minzipped Size](https://img.shields.io/bundlephobia/minzip/tag-cloud)](https://bundlephobia.com/result?p=tag-cloud)

[![Build Status](https://img.shields.io/github/actions/workflow/status/mrodrig/tag-cloud/automated-tests-workflow.yml)](https://github.com/mrodrig/tag-cloud/actions/workflows/automated-tests-workflow.yml)
[![Coverage Status](https://coveralls.io/repos/github/mrodrig/tag-cloud/badge.svg?branch=main)](https://coveralls.io/github/mrodrig/tag-cloud?branch=main)
[![Maintainability](https://api.codeclimate.com/v1/badges/8c0cc3699d054fb77abe/maintainability)](https://codeclimate.com/github/mrodrig/tag-cloud/maintainability)

## Installation

Expand All @@ -23,23 +25,35 @@ let tagCloud = require('tag-cloud');

### API

#### `tagCloud(array, callback, options)`
#### Options Configuration
* `randomize` - Boolean - Indicates whether the tags should be shuffled before the Tag Cloud is generated. [Default: true]
* `numBuckets` - Number - Number of buckets to utilize [Default: 10]
* `htmlTag` - String - The HTML tag name (ie. 'span') that you would like to be used. [Default: 'span']
* `classPrefix` - String - Class prefix for the tag classes that are generated [Default: 'bucket']
* `replacements` - Array - An array of Documents which represent replacements that should occur on attributes.
* Each document should be of the form: `{ find: 'valueToBeReplaced', replace: 'valueToBeInserted' }`
* This allows additional custom values to be inserted into attributes for further customization (ie. specifying conditional filters in URLs)
* `additionalAttributes` - Document - A JSON document specifying any additional values that you would like to be added to the tag's HTML as an attribute [Default: {}]
* If you would like to customize one of the fields to include the tag's text in the value, just use {{tag}} which will be replaced by the actual tag.
* Example: ```{href: 'http://google.com?q={{tag}}'}```
* If your tags include special characters (ie. C#) and you need to use the tag in a URL, then you can specify the value as an Object
* Example: ```{ href : { encode : true, value: 'http://google.com?q={{tag}}' } } ```

#### `tagCloud(array, options)`

Returns a `Promise<string>` that resolves with the HTML `string`.

* `array` - An array of JSON documents of the form {tagName: <String>, count: <Number>}
* `callback` - A function of the form `function (err, html)`; This function will receive any errors and/or the HTML generated.
* `options` - (Optional) A JSON document specifying any of the following fields:
* `randomize` - Boolean - Indicates whether the tags should be shuffled before the Tag Cloud is generated. [Default: true]
* `numBuckets` - Number - Number of buckets to utilize [Default: 10]
* `htmlTag` - String - The HTML tag name (ie. 'span') that you would like to be used. [Default: 'span']
* `classPrefix` - String - Class prefix for the tag classes that are generated [Default: 'bucket']
* `replacements` - Array - An array of Documents which represent replacements that should occur on attributes.
* Each document should be of the form: `{ find: 'valueToBeReplaced', replace: 'valueToBeInserted' }`
* This allows additional custom values to be inserted into attributes for further customization (ie. specifying conditional filters in URLs)
* `additionalAttributes` - Document - A JSON document specifying any additional values that you would like to be added to the tag's HTML as an attribute [Default: {}]
* If you would like to customize one of the fields to include the tag's text in the value, just use {{tag}} which will be replaced by the actual tag.
* Example: ```{href: 'http://google.com?q={{tag}}'}```
* If your tags include special characters (ie. C#) and you need to use the tag in a URL, then you can specify the value as an Object
* Example: ```{ href : { encode : true, value: 'http://google.com?q={{tag}}' } } ```
* `options` - (Optional) A JSON document specifying any of the options configuration object fields (shown above).

#### `fromStrings(array, options)`

Returns a `Promise<string>` that resolves with the HTML `string`.

Convenience method that converts your array of strings into the format needed to generate the word/tag cloud using the main `tagCloud` method listed above.

* `array` - An array of strings
* `options` - (Optional) A JSON document specifying any of the options configuration object fields (shown above).

##### tagCloud Example:

Expand All @@ -56,39 +70,14 @@ let tags = [


/* Option 1 */
tagCloud.tagCloud(tags, function (err, data) {
console.log(err, data);
});
const html = await tagCloud.tagCloud(tags);
console.log(html);

/* Option 2 */
tagCloud.tagCloud(tags, function (err, data) {
console.log(err, data);
}, {
const html = await tagCloud.tagCloud(tags, {
randomize: false
});

let promise = require('bluebird');
promise.promisifyAll(tagCloud);

/* Option 3 */
tagCloud.tagCloudAsync(tags)
.then( function (html) {
console.log(html);
})
.catch( function (err) {
console.log(err);
});

/* Option 4 */
tagCloud.tagCloudAsync(tags, {
randomize: false
})
.then( function (html) {
console.log(html);
})
.catch( function (err) {
console.log(err);
});
console.log(html);
```

Options 1 and 2 above both print out:
Expand All @@ -97,12 +86,6 @@ Options 1 and 2 above both print out:
null '<span class="bucket2" >js</span><span class="bucket4" >css</span><span class="bucket6" >less</span><span class="bucket0" >rest</span>'
```

Options 3 and 4 above both print out:

```html
<span class="bucket2" >js</span><span class="bucket4" >css</span><span class="bucket6" >less</span><span class="bucket0" >rest</span>
```

The HTML can then be styled with CSS as such:

```css
Expand All @@ -126,14 +109,6 @@ Your tag cloud can be styled to look like this:

To see the HTML and CSS used to create this, please look at the [demo](https://github.com/mrodrig/tag-cloud/tree/master/demo).

## Tests

```bash
$ npm test
```

_Note_: This requires `mocha`, `should`, `async`, and `underscore`.

## Features

- HTML Tag Cloud Generation
Expand Down
Loading

0 comments on commit 4e390b6

Please sign in to comment.