@pcg/text-kit 1.0.0-alpha.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.
- package/.turbo/turbo-build.log +15 -0
- package/README.md +243 -0
- package/dist/index.d.ts +243 -0
- package/dist/index.js +324 -0
- package/dist/index.js.map +1 -0
- package/eslint.config.cjs +14 -0
- package/package.json +26 -0
- package/src/cases.ts +317 -0
- package/src/declination.ts +23 -0
- package/src/entities.ts +41 -0
- package/src/generators.ts +16 -0
- package/src/index.ts +5 -0
- package/src/pluralize.ts +35 -0
- package/tests/cases.test.ts +196 -0
- package/tests/declination.test.ts +14 -0
- package/tests/entities.test.ts +47 -0
- package/tests/generators.test.ts +11 -0
- package/tests/pluralize.test.ts +28 -0
- package/tsconfig.json +9 -0
- package/tsconfig.lib.json +9 -0
- package/tsdown.config.ts +11 -0
- package/vitest.config.ts +19 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describe, expect,
|
|
3
|
+
test,
|
|
4
|
+
} from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { createEntityTypeNames } from '../src/entities.js';
|
|
7
|
+
|
|
8
|
+
describe('createEntityTypeNames', () => {
|
|
9
|
+
test('should return correct entity type variations for PascalCase input', () => {
|
|
10
|
+
const result = createEntityTypeNames('CodePuzzle');
|
|
11
|
+
|
|
12
|
+
expect(result.pluralEntityType).toBe('CodePuzzles');
|
|
13
|
+
expect(result.camelCaseEntityType).toBe('codePuzzle');
|
|
14
|
+
expect(result.pascalCaseEntityType).toBe('CodePuzzle');
|
|
15
|
+
expect(result.pluralCamelCaseEntityType).toBe('codePuzzles');
|
|
16
|
+
expect(result.pluralPascalCaseEntityType).toBe('CodePuzzles');
|
|
17
|
+
expect(result.createMutationName).toBe('createCodePuzzle');
|
|
18
|
+
expect(result.updateMutationName).toBe('updateCodePuzzle');
|
|
19
|
+
expect(result.deleteMutationName).toBe('deleteCodePuzzle');
|
|
20
|
+
expect(result.publishMutationName).toBe('publishCodePuzzle');
|
|
21
|
+
expect(result.unpublishMutationName).toBe('unpublishCodePuzzle');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('should return correct entity type variations for camelCase input', () => {
|
|
25
|
+
const result = createEntityTypeNames('userProfile');
|
|
26
|
+
|
|
27
|
+
expect(result.pluralEntityType).toBe('userProfiles');
|
|
28
|
+
expect(result.camelCaseEntityType).toBe('userProfile');
|
|
29
|
+
expect(result.pascalCaseEntityType).toBe('UserProfile');
|
|
30
|
+
expect(result.pluralCamelCaseEntityType).toBe('userProfiles');
|
|
31
|
+
expect(result.pluralPascalCaseEntityType).toBe('UserProfiles');
|
|
32
|
+
expect(result.createMutationName).toBe('createUserProfile');
|
|
33
|
+
expect(result.updateMutationName).toBe('updateUserProfile');
|
|
34
|
+
expect(result.deleteMutationName).toBe('deleteUserProfile');
|
|
35
|
+
expect(result.dublicateMutationName).toBe('dublicateUserProfile');
|
|
36
|
+
expect(result.publishMutationName).toBe('publishUserProfile');
|
|
37
|
+
expect(result.unpublishMutationName).toBe('unpublishUserProfile');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('should handle irregular plural forms correctly', () => {
|
|
41
|
+
const result = createEntityTypeNames('Person');
|
|
42
|
+
|
|
43
|
+
expect(result.pluralEntityType).toBe('People');
|
|
44
|
+
expect(result.pluralCamelCaseEntityType).toBe('people');
|
|
45
|
+
expect(result.pluralPascalCaseEntityType).toBe('People');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createNumericCode } from '../src/generators';
|
|
2
|
+
|
|
3
|
+
describe('Generators', () => {
|
|
4
|
+
test.each<[number, number, string]>([
|
|
5
|
+
[1, 3, '001'],
|
|
6
|
+
[3, 1, '3'],
|
|
7
|
+
[3, 2, '03'],
|
|
8
|
+
])('createNumericCode(%d, %d) = %s', (num, length, expected) => {
|
|
9
|
+
expect(createNumericCode(num, length)).toBe(expected);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPlural,
|
|
3
|
+
pluralToSingular, singularToPlural,
|
|
4
|
+
} from '../src/pluralize.js';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
describe, expect, test,
|
|
8
|
+
} from 'vitest';
|
|
9
|
+
|
|
10
|
+
describe('Is Plural', () => {
|
|
11
|
+
test('must return true for plural words', () => {
|
|
12
|
+
expect(isPlural('microcourses')).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('must return false for singular words', () => {
|
|
16
|
+
expect(isPlural('microcourse')).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('Pluralize', () => {
|
|
21
|
+
test('must convert singular to plural', () => {
|
|
22
|
+
expect(singularToPlural('microcourse')).toEqual('microcourses');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('must convert plural to singular', () => {
|
|
26
|
+
expect(pluralToSingular('microcourses')).toEqual('microcourse');
|
|
27
|
+
});
|
|
28
|
+
});
|
package/tsconfig.json
ADDED
package/tsdown.config.ts
ADDED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// / <reference types="vitest" />
|
|
2
|
+
// eslint-disable-next-line node/no-unpublished-import
|
|
3
|
+
import { defineConfig } from 'vitest/config';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
test: {
|
|
7
|
+
environment: 'node',
|
|
8
|
+
include: ['tests/**/*.test.ts'],
|
|
9
|
+
globals: true,
|
|
10
|
+
typecheck: {
|
|
11
|
+
tsconfig: './tsconfig.json',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
resolve: {
|
|
15
|
+
alias: {
|
|
16
|
+
'@': new URL('./src', import.meta.url).pathname,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|