clean-quotes 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ # This workflow will run tests using node and then publish a package to npm using Trusted Publishing (OIDC)
2
+ # For more information see: https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow
3
+
4
+ name: clean-quotes NPM Package
5
+
6
+ on:
7
+ push:
8
+ branches: [ main ]
9
+ pull_request:
10
+ branches: [ main ]
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+
16
+ # Skip Dependabot PRs for CI/CD
17
+ if: ${{ github.actor != 'dependabot[bot]' }}
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/setup-node@v4
22
+ with:
23
+ node-version: lts/krypton
24
+
25
+ - run: npm install
26
+ - run: npm test
27
+
28
+ publish-npm:
29
+ needs: build
30
+ runs-on: ubuntu-latest
31
+
32
+ # Skip Dependabot PRs
33
+ if: ${{ github.actor != 'dependabot[bot]' }}
34
+
35
+ # Required for OIDC Trusted Publishing
36
+ permissions:
37
+ contents: read
38
+ id-token: write # 👈 REQUIRED for Trusted Publishing
39
+
40
+ steps:
41
+ - uses: actions/checkout@v4
42
+ - uses: actions/setup-node@v4
43
+ with:
44
+ node-version: lts/krypton
45
+ registry-url: https://registry.npmjs.org/
46
+
47
+ - run: npm install
48
+ - run: npm publish
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # clean-quotes
2
+
3
+ <p align="center"><a href="https://nodei.co/npm/clean-quotes/"><img src="https://nodei.co/npm/clean-quotes.png"></a></a></p>
4
+ <p align="center">
5
+ <img src="https://img.shields.io/badge/License-MIT-yellow.svg">
6
+ </p>
7
+
8
+ * ✍️ Normalize quotes, dashes, and ellipsis in strings.
9
+ * ♻️ Works seamlessly with `CommonJS`, `ESM` and `TypeScript`
10
+
11
+ # 📦 Install via [NPM](https://www.npmjs.com/package/clean-quotes)
12
+
13
+ ```bash
14
+ $ npm i clean-quotes
15
+ ```
16
+
17
+ # 💻 Usage
18
+
19
+ - See examples below
20
+
21
+ ## CommonJS
22
+ ```javascript
23
+ const cleanQuotes = require('clean-quotes');
24
+
25
+ const input = `“Hello” — said the cat… ‘Are you okay?’ «Bonjour» ― こんにちは…`;
26
+ const cleanedString = cleanQuotes(input);
27
+
28
+ console.log(cleanedString);
29
+
30
+ // --| Expected output: "Hello" - said the cat... 'Are you okay?' "Bonjour" - こんにちは...
31
+ ```
32
+
33
+ ## ESM
34
+ ```javascript
35
+ import cleanQuotes from 'clean-quotes';
36
+
37
+ const input = `“Hello” — said the cat… ‘Are you okay?’ «Bonjour» ― こんにちは…`;
38
+
39
+ const cleanedString = cleanQuotes(input);
40
+ console.log(cleanedString);
41
+
42
+ // --| Expected output: "Hello" - said the cat... 'Are you okay?' "Bonjour" - こんにちは...
43
+ ```
44
+
45
+ ## TypeScript
46
+ ```javascript
47
+ import cleanQuotes from 'clean-quotes';
48
+
49
+ const input: string = `“Hello” — said the cat… ‘Are you okay?’ «Bonjour» ― こんにちは…`;
50
+ const cleanedString: string = cleanQuotes(input);
51
+
52
+ console.log(cleanedString);
53
+
54
+ // --| Expected output: "Hello" - said the cat... 'Are you okay?' "Bonjour" - こんにちは...
55
+ ```
package/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Normalize a string by standardizing quotes, dashes, ellipsis, and whitespace.
3
+ *
4
+ * - Converts all double quotes variants to standard `"`
5
+ * - Converts all single quotes/apostrophes variants to `'`
6
+ * - Converts all dash/hyphen variants to `-`
7
+ * - Converts all ellipsis variants to `...`
8
+ * - Collapses multiple spaces into a single space and trims the string
9
+ *
10
+ * Supports multi-language punctuation.
11
+ *
12
+ * @param {string | null | undefined} str - The input string to normalize
13
+ * @returns {string} The normalized string
14
+ */
15
+ declare function cleanQuotes(str: string | null | undefined): string;
16
+
17
+ export = cleanQuotes;
package/index.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * clean-quotes - ✍️ Normalize quotes, dashes, and ellipsis in strings.
3
+ * @version: v1.0.0
4
+ * @link: https://github.com/tutyamxx/clean-quotes
5
+ * @license: MIT
6
+ **/
7
+
8
+
9
+ /**
10
+ * Normalize a string by standardizing quotes, dashes, ellipsis, and whitespace.
11
+ *
12
+ * - Converts all double quotes variants to standard `"`
13
+ * - Converts all single quotes/apostrophes variants to `'`
14
+ * - Converts all dash/hyphen variants to `-`
15
+ * - Converts all ellipsis variants to `...`
16
+ * - Collapses multiple spaces into a single space and trims the string
17
+ *
18
+ * Supports multi-language punctuation.
19
+ *
20
+ * @param {string | null | undefined} str - The input string to normalize
21
+ * @returns {string} The normalized string
22
+ */
23
+ const cleanQuotes = (str) => (str ?? '')
24
+ ?.replace(/[\u201C\u201D\u00AB\u00BB\u201E\u201F\u2033\u301D\u301E\u301F]/g, '"') // --| Normalize double quotes
25
+ ?.replace(/[\u2018\u2019\u201A\u201B\u2032\u2035\u02BC\u02BB\u02BD\uFF07]/g, "'") // --| Normalize single quotes/apostrophes
26
+ ?.replace(/[\u2026\u22EF\u22F1\uFE45]/g, '...') // --| Normalize dashes/hyphens
27
+ ?.replace(/[\u2013\u2014\u2212\u2015]/g, '-') // --| Normalize ellipsis
28
+ ?.replace(/\s+/g, ' ') // --| Collapse multiple spaces into one and trim
29
+ ?.trim();
30
+
31
+ // --| CommonJS export
32
+ module.exports = cleanQuotes;
33
+
34
+ // --| ESM default export for `import` statements
35
+ module.exports.default = cleanQuotes;
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "clean-quotes",
3
+ "version": "1.0.0",
4
+ "description": "✍️ Normalize quotes, dashes, and ellipsis in strings.",
5
+ "main": "index.js",
6
+ "module": "index.js",
7
+ "types": "index.d.ts",
8
+ "exports": {
9
+ "require": "./index.js",
10
+ "import": "./index.js",
11
+ "types": "./index.d.ts"
12
+ },
13
+ "scripts": {
14
+ "test": "jest --verbose"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/tutyamxx/clean-quotes.git"
19
+ },
20
+ "keywords": [],
21
+ "author": "tuty",
22
+ "license": "MIT",
23
+ "type": "commonjs",
24
+ "bugs": {
25
+ "url": "https://github.com/tutyamxx/clean-quotes/issues"
26
+ },
27
+ "homepage": "https://github.com/tutyamxx/clean-quotes#readme",
28
+ "devDependencies": {
29
+ "jest": "^30.3.0"
30
+ }
31
+ }
@@ -0,0 +1,64 @@
1
+ const cleanQuotes = require('../index.js');
2
+
3
+ describe('cleanQuotes', () => {
4
+ test('Normalizes all types of double quotes', () => {
5
+ const input = `“Hello” «World» „Test‟ 〝Example〞`;
6
+ const expected = `"Hello" "World" "Test" "Example"`;
7
+
8
+ expect(cleanQuotes(input)).toBe(expected);
9
+ });
10
+
11
+ test('Normalizes all types of single quotes/apostrophes', () => {
12
+ const input = `‘Hello’ ‚World‛ ʼ’ ʼ’`;
13
+ const expected = `'Hello' 'World' '' ''`;
14
+
15
+ expect(cleanQuotes(input)).toBe(expected);
16
+ });
17
+
18
+ test('Normalizes all types of dashes/hyphens', () => {
19
+ const input = `– — − ―`;
20
+ const expected = `- - - -`;
21
+
22
+ expect(cleanQuotes(input)).toBe(expected);
23
+ });
24
+
25
+ test('Normalizes ellipsis variants', () => {
26
+ const input = `… … ﹅ …`;
27
+ const expected = `... ... ... ...`;
28
+
29
+ expect(cleanQuotes(input)).toBe(expected);
30
+ });
31
+
32
+ test('Collapses multiple spaces and trims', () => {
33
+ const input = ` Hello world `;
34
+ const expected = `Hello world`;
35
+
36
+ expect(cleanQuotes(input)).toBe(expected);
37
+ });
38
+
39
+ test('Handles null and undefined', () => {
40
+ expect(cleanQuotes(null)).toBe('');
41
+ expect(cleanQuotes(undefined)).toBe('');
42
+ });
43
+
44
+ test('Works with multi-language text', () => {
45
+ const input = `“Hello” — said the cat… ‘Are you okay?’ «Bonjour» ― こんにちは…`;
46
+ const expected = `"Hello" - said the cat... 'Are you okay?' "Bonjour" - こんにちは...`;
47
+
48
+ expect(cleanQuotes(input)).toBe(expected);
49
+ });
50
+
51
+ test('Preserves emoji and special characters', () => {
52
+ const input = `“Hello 😺” — こんにちは…`;
53
+ const expected = `"Hello 😺" - こんにちは...`;
54
+
55
+ expect(cleanQuotes(input)).toBe(expected);
56
+ });
57
+
58
+ test('Combines all features in one complex string', () => {
59
+ const input = `‘Test’ – “Example”… ― «多言語»… ✅`;
60
+ const expected = `'Test' - "Example"... - "多言語"... ✅`;
61
+
62
+ expect(cleanQuotes(input)).toBe(expected);
63
+ });
64
+ });