Skip to content

Commit

Permalink
Merge pull request #498 from no-chris/add-ultimateguitar-filer
Browse files Browse the repository at this point in the history
Add Ultimate Guitar filter
  • Loading branch information
no-chris committed Jan 12, 2022
2 parents ba6071f + 3bd291e commit 6ea40ad
Show file tree
Hide file tree
Showing 21 changed files with 278 additions and 6,250 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

## Available packages

| Package name | Desription |
| ------------------------------------------------------------------------------------------ | -------------------------------------------------------- |
| [chord-symbol](https://github.com/no-chris/chord-symbol/tree/master/packages/chord-symbol) | The core library for parsing and rendering chord symbols |
| Package name | Desription |
| ------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------- |
| [chord-symbol](https://github.com/no-chris/chord-symbol/tree/master/packages/chord-symbol) | The core library for parsing and rendering chord symbols |
| [chord-symbol-ultimateguitar](https://github.com/no-chris/chord-symbol/tree/master/packages/chord-symbol-ultimateguitar) | Generate Ultimate Guitar-friendly chord symbols |
4 changes: 1 addition & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ const presets = [
'@babel/preset-env',
{
targets: {
browsers: 'defaults',
browsers: 'last 2 versions',
},
useBuiltIns: 'usage',
corejs: '3',
},
],
];
Expand Down
8 changes: 8 additions & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ module.exports = {
statements: 100,
},
},

// whitelisting local modules in the node_modules folder
transformIgnorePatterns: [
'<rootDir>.*(node_modules)(?!.*chord-symbol.*).*$',
],
moduleNameMapper: {
'chord-symbol': '<rootDir>/packages/chord-symbol/src/index.js',
},
};
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": ["packages/*"],
"version": "2.1.0",
"version": "3.0.0-beta.2",
"npmClient": "yarn",
"preid": "beta",
"changelog": {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "chord-symbol",
"name": "monorepo-chord-symbol",
"version": "2.1.0",
"description": "Chord symbol parser and renderer",
"main": "lib/chord-symbol.js",
"author": "Christophe Noël",
"license": "MIT",
"repository": {
Expand Down
19 changes: 19 additions & 0 deletions packages/chord-symbol-ultimateguitar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ChordSymbolUltimateGuitar

Modify the `ChordSymbol` output to be closer with the chord symbols accepted by the Ultimate Guitar website.
If you use `ChordSymbol` to generate chord charts to be submitted on this website, you definitely want to use this filter.

## Usage

```javascript
import { chordParserFactory, chordRendererFactory } from 'chord-symbol';
import chordSymbolUltimateGuitar from '../src/chordSymbolUltimateGuitar';

const parsed = chordParserFactory()('C7(#9)');
const rendered = chordRendererFactory({
customFilters: [chordSymbolUltimateGuitar()],
useShortNamings: true,
})(parsed);

// C7#9
```
13 changes: 13 additions & 0 deletions packages/chord-symbol-ultimateguitar/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-env node */
const presets = [
[
'@babel/preset-env',
{
targets: {
browsers: 'last 2 versions',
},
},
],
];

module.exports = { presets };
11 changes: 11 additions & 0 deletions packages/chord-symbol-ultimateguitar/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-env node */
const baseConfig = require('../../jest.config.base');
const packageJson = require('./package');

module.exports = {
...baseConfig,
name: packageJson.name,
displayName: packageJson.name,

rootDir: '../..',
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions packages/chord-symbol-ultimateguitar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "chord-symbol-ultimateguitar",
"version": "3.0.0-beta.2",
"description": "Format chord symbols in an Ultimate Guitar-friendly way",
"author": "Christophe Noël",
"homepage": "https://github.com/no-chris/chord-symbol/tree/main/packages/chord-symbol-ultimateguitar#readme",
"license": "MIT",
"main": "lib/chord-symbol-ultimateguitar.js",
"directories": {
"lib": "lib",
"test": "src"
},
"files": [
"lib"
],
"repository": {
"type": "git",
"url": "git+https://github.com/no-chris/chord-symbol.git"
},
"scripts": {
"build": "webpack"
},
"bugs": {
"url": "https://github.com/no-chris/chord-symbol/issues"
},
"keywords": [
"chord",
"chords",
"chord-parsing",
"guitar",
"guitar-chords",
"music",
"music-theory",
"parser",
"piano",
"ukulele"
],
"dependencies": {
"chord-symbol": "^3.0.0-beta.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const chordSymbolUltimateGuitar = () => {
return (chord) => {
chord.formatted.symbol = chord.formatted.symbol
.replace(/[() ]/g, '')
.replace('mM', 'mMaj')
.replace('°', 'dim');

return chord;
};
};

export default chordSymbolUltimateGuitar;
12 changes: 12 additions & 0 deletions packages/chord-symbol-ultimateguitar/tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
env: {
jest: true,
node: true,
},
rules: {
'no-restricted-imports': ['off'],
'max-len': ['off'],
'max-params': ['warn', { max: 6 }],
'max-lines': ['error', { max: 550 }],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
chordParserFactory,
chordRendererFactory,
} from '../../chord-symbol/src/index';
import chordSymbolUltimateGuitar from '../src/chordSymbolUltimateGuitar';

describe('chordSymbolUltimateGuitar', () => {
test('Module', () => {
expect(chordSymbolUltimateGuitar).toBeInstanceOf(Function);
expect(chordSymbolUltimateGuitar()).toBeInstanceOf(Function);
});
});

describe.each([
['remove parenthesis', 'A7(#9)', 'A7#9'],
['replace ° with "dim" in dim chords', 'A°', 'Adim'],
['replace ° with "dim" in dim7 chords', 'A7°', 'Adim7'],
['replace mM with "mMaj"', 'AmM7', 'AmMaj7'],
['remove spaces', 'C(#9)', 'Cadd#9'],
])('%s', (title, input, output) => {
test(input + ' => ' + output, () => {
const parsed = chordParserFactory()(input);
const rendered = chordRendererFactory({
customFilters: [chordSymbolUltimateGuitar()],
useShortNamings: true,
})(parsed);
expect(rendered).toEqual(output);
});
});
47 changes: 47 additions & 0 deletions packages/chord-symbol-ultimateguitar/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-env node */
const path = require('path');

const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const buildDir = 'lib';

const config = {
target: 'web',
mode: 'production',
devtool: 'source-map',

entry: {
'chord-symbol-ultimateguitar': './src/chordSymbolUltimateGuitar.js',
},

output: {
filename: '[name].js',
path: path.resolve(process.cwd(), buildDir),
library: 'chord-symbol-ultimateguitar',
libraryTarget: 'umd',
// https://github.com/webpack/webpack/pull/8625
globalObject: "typeof self !== 'undefined' ? self : this",
},

optimization: {
minimize: false,
},

performance: {
hints: false,
},

plugins: [new CleanWebpackPlugin()],

module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
},
};

module.exports = config;
4 changes: 1 addition & 3 deletions packages/chord-symbol/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ const presets = [
'@babel/preset-env',
{
targets: {
browsers: 'defaults',
browsers: 'last 2 versions',
},
useBuiltIns: 'usage',
corejs: '3',
},
],
];
Expand Down
Loading

0 comments on commit 6ea40ad

Please sign in to comment.