mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-24 12:15:32 +08:00
* chore(deps-dev): bump eslint-plugin-unicorn from 66.0.0 to 68.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 66.0.0 to 68.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v66.0.0...v68.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 68.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * style: fix no-useless-coercion * style: fix prefer-boolean-return * style: fix no-useless-logical-operand * style: fix prefer-single-replace * style: fix consistent-conditional-object-spread * style: fix no-useless-else * style: fix prefer-unicode-code-point-escapes * style: fix operator-assignment * style: fix prefer-continue * style: fix prefer-math-constants * style: fix prefer-hoisting-branch-code * style: fix prefer-array-slice * style: fix consistent-class-member-order * style: fix no-return-array-push * style: fix prefer-promise-with-resolvers * style: fix no-array-concat-in-loop * style: fix no-loop-iterable-mutation * style: fix no-invalid-argument-count * style: fix no-duplicate-if-branches * style: fix prefer-else-if * style: fix no-unreadable-for-of-expression * style: fix logical-assignment-operators * style: fix default-export-style * style: revert false positve in prefer-type-literal-last in #22274 * style: fix arrow-body-style * style: add v68 recommended preset * style: refactor GraphQL queries to use template literals for better readability --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
128 lines
2.7 KiB
TypeScript
128 lines
2.7 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { camelcase, camelcaseKeys } from './camelcase-keys';
|
|
|
|
describe('test camelcase keys', () => {
|
|
it('case 1 normal', () => {
|
|
const obj = {
|
|
tool: 'too',
|
|
tool_name: 'too_name',
|
|
|
|
a_b: 1,
|
|
a: 1,
|
|
b: {
|
|
c_d: 1,
|
|
},
|
|
};
|
|
|
|
expect(camelcaseKeys(obj)).toStrictEqual({
|
|
tool: 'too',
|
|
toolName: 'too_name',
|
|
|
|
aB: 1,
|
|
a: 1,
|
|
b: {
|
|
cD: 1,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('case 2: key has number', () => {
|
|
const obj = {
|
|
b147da0eaecbea00aeb62055: {
|
|
data: {},
|
|
},
|
|
a_c11ab_Ac: [
|
|
{
|
|
a_b: 1,
|
|
},
|
|
1,
|
|
],
|
|
};
|
|
|
|
expect(camelcaseKeys(obj)).toStrictEqual({
|
|
b147da0eaecbea00aeb62055: {
|
|
data: {},
|
|
},
|
|
aC11abAc: [
|
|
{
|
|
aB: 1,
|
|
},
|
|
1,
|
|
],
|
|
});
|
|
});
|
|
|
|
it('case 3: not a object', () => {
|
|
const value = 1;
|
|
expect(camelcaseKeys(value)).toBe(value);
|
|
});
|
|
|
|
it('case 4: nullable value', () => {
|
|
let value = null as any;
|
|
expect(camelcaseKeys(value)).toBe(value);
|
|
|
|
value = undefined;
|
|
expect(camelcaseKeys(value)).toBe(value);
|
|
|
|
value = NaN;
|
|
expect(camelcaseKeys(value)).toBe(value);
|
|
});
|
|
|
|
it('case 5: array', () => {
|
|
const arr = [
|
|
{
|
|
a_b: 1,
|
|
},
|
|
null,
|
|
undefined,
|
|
0,
|
|
-0,
|
|
Infinity,
|
|
{
|
|
a_b: 1,
|
|
},
|
|
];
|
|
|
|
expect(camelcaseKeys(arr)).toStrictEqual([
|
|
{
|
|
aB: 1,
|
|
},
|
|
null,
|
|
undefined,
|
|
0,
|
|
-0,
|
|
Infinity,
|
|
{
|
|
aB: 1,
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('case 6: filter out mongo id', () => {
|
|
const obj = {
|
|
_id: '123',
|
|
a_b: 1,
|
|
collections: {
|
|
posts: {
|
|
'661bb93307d35005ba96731b': {},
|
|
},
|
|
},
|
|
};
|
|
|
|
expect(camelcaseKeys(obj)).toStrictEqual({
|
|
id: '123',
|
|
aB: 1,
|
|
collections: {
|
|
posts: {
|
|
'661bb93307d35005ba96731b': {},
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it('case 7: start with underscore should not camelcase', () => {
|
|
expect(camelcase('_id')).toBe('id');
|
|
});
|
|
});
|