Skip to content

Commit

Permalink
fix: handle already existing seperator in a string or multiple sepera…
Browse files Browse the repository at this point in the history
…tors. also package

updates

BREAKING CHANGE: spaceSlug(['space-slug']) will now return "space-slug" instead of "spaceslug"
  • Loading branch information
TimMikeladze committed Feb 17, 2024
1 parent aada64a commit 30541f4
Show file tree
Hide file tree
Showing 7 changed files with 4,075 additions and 5,609 deletions.
5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

yarn test:ci
yarn lint-staged
90 changes: 45 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"lint:fix": "yarn lint --fix && prettier --write .",
"test": "vitest",
"test:ci": "vitest run --coverage",
"prepare": "husky install",
"prepare": "husky",
"commit": "cz",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
Expand Down Expand Up @@ -89,61 +89,61 @@
"node": ">=14.0.0"
},
"devDependencies": {
"@babel/core": "7.22.10",
"@babel/preset-env": "7.22.10",
"@babel/preset-react": "7.22.5",
"@babel/preset-typescript": "7.22.5",
"@commitlint/cli": "17.6.7",
"@commitlint/config-conventional": "17.6.7",
"@babel/core": "7.23.9",
"@babel/preset-env": "7.23.9",
"@babel/preset-react": "7.23.3",
"@babel/preset-typescript": "7.23.3",
"@commitlint/cli": "18.6.1",
"@commitlint/config-conventional": "18.6.2",
"@ryansonshine/commitizen": "4.2.8",
"@ryansonshine/cz-conventional-changelog": "3.3.4",
"@storybook/addon-essentials": "7.2.1",
"@storybook/addon-interactions": "7.2.1",
"@storybook/addon-links": "7.2.1",
"@storybook/blocks": "7.2.1",
"@storybook/react": "7.2.1",
"@storybook/react-webpack5": "7.2.1",
"@storybook/addon-essentials": "7.6.16",
"@storybook/addon-interactions": "7.6.16",
"@storybook/addon-links": "7.6.16",
"@storybook/blocks": "7.6.16",
"@storybook/react": "7.6.16",
"@storybook/react-webpack5": "7.6.16",
"@storybook/storybook-deployer": "2.8.16",
"@storybook/testing-library": "0.2.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.0.0",
"@types/node": "20.4.8",
"@types/react": "18.2.19",
"@types/react-dom": "18.2.7",
"@types/react-test-renderer": "18.0.0",
"@typescript-eslint/eslint-plugin": "6.3.0",
"@typescript-eslint/parser": "6.3.0",
"@vitejs/plugin-react": "^4.0.3",
"@vitest/coverage-v8": "^0.34.0",
"@storybook/testing-library": "0.2.2",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"@types/node": "20.11.19",
"@types/react": "18.2.56",
"@types/react-dom": "18.2.19",
"@types/react-test-renderer": "18.0.7",
"@typescript-eslint/eslint-plugin": "7.0.1",
"@typescript-eslint/parser": "7.0.1",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-v8": "^1.3.0",
"babel-loader": "9.1.3",
"concurrently": "8.2.0",
"eslint": "8.46.0",
"concurrently": "8.2.2",
"eslint": "8.56.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.28.0",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-prefer-arrow": "1.2.3",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-react": "7.33.1",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-sort-class-members": "^1.18.0",
"eslint-plugin-storybook": "0.6.13",
"eslint-plugin-typescript-sort-keys": "2.3.0",
"eslint-plugin-unused-imports": "3.0.0",
"husky": "8.0.3",
"jsdom": "^22.1.0",
"lint-staged": "13.2.3",
"prettier": "3.0.1",
"eslint-plugin-sort-class-members": "^1.20.0",
"eslint-plugin-storybook": "0.8.0",
"eslint-plugin-typescript-sort-keys": "3.1.0",
"eslint-plugin-unused-imports": "3.1.0",
"husky": "9.0.11",
"jsdom": "^24.0.0",
"lint-staged": "15.2.2",
"prettier": "3.2.5",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-test-renderer": "18.2.0",
"release-it": "16.1.3",
"storybook": "7.2.1",
"tsdoc-markdown": "^0.0.4",
"tsup": "7.2.0",
"typescript": "5.1.6",
"vitest": "^0.34.0",
"release-it": "17.0.5",
"storybook": "7.6.16",
"tsdoc-markdown": "^0.3.0",
"tsup": "8.0.2",
"typescript": "5.3.3",
"vitest": "^1.3.0",
"yalc": "1.0.0-pre.53"
},
"resolutions": {
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ export const digits =

export const cleanString = (inputString: string, separator: string) =>
inputString
.replace(/[^a-zA-Z0-9\s]+/g, '')
.replace(/\s+/g, separator)
.trim();
.trim()
.replace(new RegExp(`[^a-zA-Z0-9${separator}]+`, 'g'), '')
.replace(new RegExp(`(?:${separator}){2,}`, 'g'), separator)
.replace(new RegExp(`^${separator}|${separator}$`, 'g'), '');

// eslint-disable-next-line no-underscore-dangle
const _uniqueSpaceSlug = async (
Expand Down
2 changes: 1 addition & 1 deletion tests/setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, afterEach } from 'vitest';
import { cleanup } from '@testing-library/react';
import matchers from '@testing-library/jest-dom/matchers';
import * as matchers from '@testing-library/jest-dom/matchers';

expect.extend(matchers);

Expand Down
11 changes: 11 additions & 0 deletions tests/spaceSlug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ describe('spaceSlug', () => {
dictionary,
})
).toBe('foobar-jabba');

expect(spaceSlug(['space-slug'])).toEqual('space-slug');

expect(spaceSlug(['space--slug'])).toEqual('space-slug');

expect(
spaceSlug([
`-#
space---slug-@-`,
])
).toEqual('space-slug');
});
});

Expand Down
File renamed without changes.
Loading

0 comments on commit 30541f4

Please sign in to comment.