-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
root: true, | ||
extends: [require.resolve('@nzyme/eslint/typescript')], | ||
parserOptions: { | ||
project: `${__dirname}/tsconfig.json`, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@nzyme/typography", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"sideEffects": false, | ||
"repository": "https://github.com/nzymejs/nzyme.git", | ||
"author": "Michał Kędrzyński <m.kedrzynski@gmail.com>", | ||
"private": true, | ||
"scripts": { | ||
"eslint": "eslint . --fix --cache", | ||
"build": "tsc --build" | ||
}, | ||
"dependencies": { | ||
"@nzyme/types": "*", | ||
"@nzyme/utils": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const spaceAfterShortWordRegex = /([\s(]|^)(\w{1,2})\s/gmu; | ||
const longWordRegex = /\s([^\s]{12,})/gmu; | ||
|
||
/** | ||
* Search for any word, that is 3 or less characters long | ||
* Such short words should not end up on the end of the line. | ||
* We add non-breakable space at the end of the word. | ||
* Source: https://boanastudio.com/blog/text-in-responsive-web-design | ||
* @param text Text to fix | ||
*/ | ||
export function fixOrphans(text: string) { | ||
// use [^\s] to match anything but whitespace characters | ||
return ( | ||
text | ||
.replace(spaceAfterShortWordRegex, (search, whitespace: string, word: string) => { | ||
// replace spaces between short words with a non-breakable space | ||
// do not swap it with any other character! | ||
return whitespace + word + '\xa0'; | ||
}) | ||
// roll back the operation if following word has 12 or more letters | ||
.replace(longWordRegex, (search, group: string) => { | ||
return ' ' + group; | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './fixOrphans.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"tsBuildInfoFile": "./dist/.tsbuildinfo", | ||
"rootDir": "./src" | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.json"], | ||
"references": [ | ||
{ | ||
"path": "../types/tsconfig.json" | ||
}, | ||
{ | ||
"path": "../utils/tsconfig.json" | ||
} | ||
] | ||
} |