Skip to content

Commit

Permalink
2.5.8 (#78)
Browse files Browse the repository at this point in the history
* Service mark

* Copyrights

* Swap params order

* Update dependencies

* Update version
  • Loading branch information
surfinzap authored Sep 22, 2024
1 parent c4d988b commit 6fa384c
Show file tree
Hide file tree
Showing 27 changed files with 326 additions and 242 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@



## 2.5.8 //
## 2.5.8 // 2024-09-22

### 💪 Improvements
- Fix Service Mark, when indicated in brackets, i.e. `Brand(sm)``Brand℠`

### 🔨 Maintenance
- Add a build automation
- Automate copyright notice updates in source and dist files
- Refactor code for Registered Trademark (®), Trademark (™), Copyright (©), and Sound Recording Copyright (℗)
- Update dev dependencies to their latest versions



Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Typopo fixes symbols:
- copyright ((c)2020 → © 2020)
- sound recording copyright ((p)2020 → ℗ 2020)
- registered trademark (Brand(r) → Brand®)
- service mark (Brand(sm) → Brand℠)
- trademark (Brand(tm) → Brand™)
- plus-minus sign (+-, -+ → ±)
- square and cube exponents (e.g. 100 µm² → 100 µm², 50 km³ → 50 km³)
Expand Down
4 changes: 2 additions & 2 deletions dist/typopo.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/typopo_dist.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typopo",
"version": "2.5.7",
"version": "2.5.8",
"description": "Fix frequent microtypography errors in multiple languages. Write neat texts without bothering about typography rules. Typopo works for English, German, Slovak, Czech and Rusyn language.",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -48,7 +48,7 @@
"babelify": "^10.0.0",
"browser-sync": "^3.0.2",
"browserify": "^17.0.0",
"eslint": "^9.10.0",
"eslint": "^9.11.0",
"gulp": "^5.0.0",
"gulp-babel": "^8.0.0",
"gulp-cli": "^3.0.0",
Expand Down
32 changes: 16 additions & 16 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/lib/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function withFunctionInReturn(string, locale) {


/* test */
describe('Test case (en):\n', () => {
describe('Test case (en-us):\n', () => {
let testCase = {
...somePartialTestCase,
};
Expand Down
22 changes: 0 additions & 22 deletions src/lib/symbols/copyright.js

This file was deleted.

60 changes: 60 additions & 0 deletions src/lib/symbols/copyrights.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {addSpaceBeforeSymbol} from "../whitespace/spaces";
import {addNbspAfterSymbol,
replaceSpacesWithNbspAfterSymbol} from "../whitespace/nbsp";


/**
* Replaces occurrences of a copyright indication in a string followed by a year.
*
* Example: Company (c) 2017 -> Company © 2017
*
* @param {string} string - The input string where marks will be replaced.
* @param {string} copyrightLetter - The pattern for the copyright (e.g., “p” for sound recording copyright).
* @param {string} copyrightSign - The symbol to replace the pattern with (e.g., “©” for copyright).
* @param {Object} locale - An object w/ locale-specific symbols.
* @returns {string} - The string with the specified copyrights replaced.
*/
export function replaceCopyright(string, copyrightLetter, copyrightSign, locale) {
return string.replace(
new RegExp(
"(\\(" + copyrightLetter + "\\))"
+ "([" + locale.spaces + "]*)"
+ "(" + locale.cardinalNumber + ")",
"gi"
),
copyrightSign + "$2$3"
);
}



/**
* Consolidates spaces around copyright sign
*
* @param {string} string - The input string where marks will be replaced.
* @param {string} copyrightSign - The sign of choice, either © or ℗
* @param {Object} locale - An object w/ locale-specific symbols.
* @returns {string} - The string with the consolidated spaces around the copyright sign
*/
export function consolidateSpaces(string, copyrightSign, locale) {
string = addSpaceBeforeSymbol(string, copyrightSign, locale);
string = addNbspAfterSymbol(string, copyrightSign, locale);
string = replaceSpacesWithNbspAfterSymbol(string, copyrightSign, locale);
return string;
}


/**
* Fixes occurrences of copyright (©), and sound recording copyright (℗) in a given string.
*
* @param {string} string - The input string to be fixed.
* @param {Object} locale - An object w/ locale-specific symbols
* @returns {string} - The string with marks replaced.
*/
export function fixCopyrights(string, locale) {
string = replaceCopyright(string, "c", locale.copyright, locale);
string = consolidateSpaces(string, locale.copyright, locale);
string = replaceCopyright(string, "p", locale.soundRecordingCopyright, locale);
string = consolidateSpaces(string, locale.soundRecordingCopyright, locale);
return string;
}
40 changes: 40 additions & 0 deletions src/lib/symbols/marks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Replaces occurrences of a specific mark in a string.
*
* Example: Company (tm) -> Company™
*
* @param {string} string - The input string where marks will be replaced.
* @param {string} markPattern - The pattern for the mark (e.g., “tm” for trademark).
* @param {string} replacementMark - The symbol to replace the pattern with (e.g., “™” for trademark).
* @param {Object} locale - An object w/ locale-specific symbols.
* @returns {string} - The string with the specified marks replaced.
*/
export function replaceMark(string, markPattern, replacementMark, locale) {
return string.replace(
new RegExp(
"([^0-9]|^)"
+ "([" + locale.spaces + "]*)"
+ "(\\(" + markPattern + "\\)|" + replacementMark + ")",
"gi"
),
"$1" + replacementMark
);
}



/**
* Fixes occurrences of registered trademark (®), service mark (℠) and trademark (™) in a given string.
*
* @param {string} string - The input string to be fixed.
* @param {Object} locale - An object w/ locale-specific symbols
* @returns {string} - The string with marks replaced.
*/
export function fixMarks(string, locale) {

string = replaceMark(string, "r", locale.registeredTrademark, locale);
string = replaceMark(string, "sm", locale.serviceMark, locale);
string = replaceMark(string, "tm", locale.trademark, locale);

return string;
}
15 changes: 0 additions & 15 deletions src/lib/symbols/registered-trademark.js

This file was deleted.

23 changes: 0 additions & 23 deletions src/lib/symbols/sound-recording-copyright.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/lib/symbols/trademark.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/lib/whitespace/nbsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export function addNbspBeforeSingleLetter(string, locale) {
@param {string} string — input text for identification
@returns {string} — output with correctly added non-breaking space
*/
export function addNbspAfterSymbol(string, locale, symbol) {
export function addNbspAfterSymbol(string, symbol, locale) {
let pattern = "("+ symbol +")([^" + locale.spaces + "])";
let re = new RegExp(pattern, "g");
let replacement = "$1" + locale.nbsp + "$2";
Expand All @@ -351,7 +351,7 @@ export function addNbspAfterSymbol(string, locale, symbol) {
@param {string} string — input text for identification
@returns {string} — output with correctly placed non-breaking space
*/
export function replaceSpacesWithNbspAfterSymbol(string, locale, symbol) {
export function replaceSpacesWithNbspAfterSymbol(string, symbol, locale) {
let pattern = "("+ symbol +")([" + locale.spaces + "])";
let re = new RegExp(pattern, "g");
let replacement = "$1" + locale.nbsp;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/whitespace/spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export function addSpaceAfterClosingBrackets(string, locale) {



export function addSpaceBeforeSymbol(string, locale, symbol) {
export function addSpaceBeforeSymbol(string, symbol, locale) {
let pattern = "([^" + locale.spaces + locale.openingBrackets + "])("+ symbol +")";
let re = new RegExp(pattern, "g");
let replacement = "$1" + locale.space + "$2";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/words/abbreviations.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function fixInitials(string, locale) {
[2] Change multiple-word abbreviations from all locales abbr. patterns
[3] Identify and fix multiple-word abbreviations before the word
[4] Identify and fix multiple-word abbreviations after the word or on their own

@param {string} input text for identification
@returns {string} corrected output
*/
Expand Down
3 changes: 2 additions & 1 deletion src/locale/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ export default class Locale {
this.ampersand = "&";
this.sectionSign = "§";
this.copyright = "©";
this.registeredTrademark = "®";
this.soundRecordingCopyright = "℗";
this.registeredTrademark = "®";
this.serviceMark = "℠";
this.trademark = "™";
this.plus = "+";
this.minus = "−";
Expand Down
Loading

0 comments on commit 6fa384c

Please sign in to comment.