Skip to content

Commit

Permalink
Merge pull request #62 from ComponentDriven/norbert/no-lodash
Browse files Browse the repository at this point in the history
replace lodash
  • Loading branch information
shilman authored Feb 16, 2023
2 parents e86f8c6 + 4a3b146 commit 6f29d0c
Show file tree
Hide file tree
Showing 8 changed files with 1,163 additions and 901 deletions.
54 changes: 28 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,33 @@
"url": "https://github.com/ComponentDriven/csf.git"
},
"license": "MIT",
"files": [
"dist/**/*",
"README.md",
"*.js",
"*.d.ts"
],
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"require": "./dist/index.js",
"browser": "./dist/index.mjs",
"node": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"README.md",
"*.js",
"*.d.ts"
],
"scripts": {
"build": "tsup ./src/index.ts --format esm,cjs --dts",
"build": "tsup ./src/index.ts --format esm,cjs --dts --treeshake --minify",
"check": "tsc",
"lint": "eslint src --ext .ts",
"test": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-vm-modules jest",
"release": "yarn build && auto shipit"
"release": "yarn build && auto shipit",
"test": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-vm-modules jest"
},
"prettier": "@storybook/linter-config/prettier.config",
"eslintConfig": {
"extends": [
"@storybook/eslint-config-storybook"
],
"parserOptions": {
"project": [
"./tsconfig.json"
Expand All @@ -57,6 +58,9 @@
}
}
},
"extends": [
"@storybook/eslint-config-storybook"
],
"rules": {
"import/no-unresolved": "error",
"jest/expect-expect": [
Expand All @@ -70,38 +74,35 @@
]
}
},
"prettier": "@storybook/linter-config/prettier.config",
"jest": {
"preset": "ts-jest/presets/default-esm",
"extensionsToTreatAsEsm": [
".ts"
],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"preset": "ts-jest/presets/default-esm",
"roots": [
"<rootDir>/src"
],
"testEnvironment": "node",
"transform": {
"^.+\\.tsx?$": [
"ts-jest",
{
"useESM": true
}
]
},
"testEnvironment": "node",
"roots": [
"<rootDir>/src"
]
}
},
"dependencies": {
"expect-type": "^0.14.2",
"lodash": "^4.17.15",
"type-fest": "^2.19.0"
},
"devDependencies": {
"@auto-it/released": "^10.37.6",
"@ngard/tiny-isequal": "^1.1.0",
"@storybook/eslint-config-storybook": "^3.1.2",
"@types/jest": "^29.2.0",
"@types/lodash": "^4.14.149",
"@types/node": "^18.11.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
Expand All @@ -111,19 +112,20 @@
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.4",
"expect-type": "^0.14.2",
"jest": "^29.3.1",
"prettier": "^2.7.1",
"ts-jest": "^29.0.3",
"tsup": "^6.4.0",
"typescript": "^4.8.4"
},
"publishConfig": {
"access": "public"
},
"auto": {
"plugins": [
"npm",
"released"
]
},
"publishConfig": {
"access": "public"
}
}
5 changes: 4 additions & 1 deletion src/includeConditionalArg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import isEqual from 'lodash/isEqual';
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable import/no-extraneous-dependencies */
/* @ts-expect-error (has no typings) */
import { isEqual } from '@ngard/tiny-isequal';
import { Args, Globals, InputType, Conditional } from './story.js';

const count = (vals: any[]) => vals.map((v) => typeof v !== 'undefined').filter(Boolean).length;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import startCase from 'lodash/startCase';
import { toStartCaseStr } from './toStartCaseStr';

/**
* Remove punctuation and illegal characters from a story ID.
Expand Down Expand Up @@ -34,7 +34,7 @@ export const toId = (kind: string, name?: string) =>
/**
* Transform a CSF named export into a readable story name
*/
export const storyNameFromExport = (key: string) => startCase(key);
export const storyNameFromExport = (key: string) => toStartCaseStr(key);

type StoryDescriptor = string[] | RegExp;
export interface IncludeExcludeOptions {
Expand Down
3 changes: 2 additions & 1 deletion src/story.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable import/no-extraneous-dependencies */
/* global HTMLElement */
import { expectTypeOf } from 'expect-type';
import { Except, SetOptional } from 'type-fest';
import {
Renderer,
Args,
Expand Down
4 changes: 2 additions & 2 deletions src/story.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RemoveIndexSignature, Simplify, UnionToIntersection } from 'type-fest';
import { SBScalarType, SBType } from './SBType.js';
import type { RemoveIndexSignature, Simplify, UnionToIntersection } from 'type-fest';
import type { SBScalarType, SBType } from './SBType';

export * from './SBType.js';
export type StoryId = string;
Expand Down
20 changes: 20 additions & 0 deletions src/toStartCaseStr.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { toStartCaseStr } from './toStartCaseStr';

test.each([
['snake_case', 'Snake Case'],
['kebab-case', 'Kebab Case'],
['camelCase', 'Camel Case'],
['camelCase1', 'Camel Case 1'],
['camelCase1a', 'Camel Case 1a'],
['camelCase1A', 'Camel Case 1A'],
['camelCase1A2', 'Camel Case 1A 2'],
['camelCase1A2b', 'Camel Case 1A 2b'],
['camelCase1A2B', 'Camel Case 1A 2B'],
['camelCase1A2B3', 'Camel Case 1A 2B 3'],
['__FOOBAR__', 'FOOBAR'],
['__FOO_BAR__', 'FOO BAR'],
[' FOO BAR', 'FOO BAR'],
['1. Fooo', '1. Fooo'],
])('%s', (str, expected) => {
expect(toStartCaseStr(str)).toBe(expected);
});
9 changes: 9 additions & 0 deletions src/toStartCaseStr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function toStartCaseStr(str: string) {
return str
.replace(/_/g, ' ')
.replace(/-/g, ' ')
.replace(/([a-z])([A-Z])/g, (str2, $1, $2) => `${$1} ${$2}`)
.replace(/([a-z])([0-9])/gi, (str2, $1, $2) => `${$1} ${$2}`)
.replace(/(\s|^)(\w)/g, (str2, $1, $2) => $1 + $2.toUpperCase())
.trim();
}
Loading

0 comments on commit 6f29d0c

Please sign in to comment.