huynhsamha/js-convert-case

Nested array properties are not converted

maxusr opened this issue ยท 4 comments

Your code is amazing. But when a nested property is an array of objects the properties of these objects are not converted. I created a fork to handle it but i guess you use TS it'll better if you can add this functionnality. And maybe convert an array of objects directly cause now if i pass an array of objects to snakeKeys for example, the properties of these objects are not converted.

@maxusr Thanks for your contribution, I'll fix this problem and release a new updated version soon ๐Ÿ‘

@maxusr I've released a new version on NPM that supports your issue. ๐Ÿ’ช ๐Ÿ’ช ๐Ÿ’ช
Please let me any feedback if it doesn't work for you. ๐Ÿ™

@huynhsamha sorry it still doesn't work for me.
Here's what i got from your version 4.1.0

{
	"data": {
		"id": 87608,
		"first_name": "Jillian",
		"last_name": "Mante",
		"birth_date": "2010-11-02T10:18:30.205Z",
		"email": "Jillian_Mante7@gmail.com",
		"created_at": "2020-08-16T10:08:54.400Z",
		"updated_at": "2020-08-11T16:16:49.450Z",
		"last_flight": {
			"id": 44389,
			"departure_date": "2020-08-15T10:49:53.751Z",
			"arrival_date": "2020-08-16T09:49:53.751Z"
		},
		"landing_grounds": [
			{
				"id": 36095,
				"location": {
					"name": "Lang Mount",
					"locality": "Rennes",
					"country": "France",
					"postalCode": "55890-0219",
					"latitude": 48.111981,
					"longitude": -1.674291
				},
				"name": "Lang Mount",
				"createdAt": "2020-08-06T02:44:41.031Z",
				"updatedAt": "2020-08-03T06:59:56.938Z"
			}
		]
	}
}

And here's what i got from my fork...

{
	"data": {
		"id": 45864,
		"first_name": "Theresa",
		"last_name": "Brekke",
		"birth_date": "2018-09-04T23:37:40.941Z",
		"email": "Theresa.Brekke@yahoo.com",
		"created_at": "2020-08-11T21:05:53.650Z",
		"updated_at": "2020-07-27T09:40:45.584Z",
		"last_flight": {
			"id": 41474,
			"departure_date": "2020-08-17T20:35:26.170Z",
			"arrival_date": "2020-08-18T04:35:26.170Z"
		},
		"landing_grounds": [
			{
				"id": 39358,
				"location": {
					"name": "Isadore Place",
					"locality": "Marseille",
					"country": "France",
					"postal_code": "46364-9033",
					"latitude": 43.285413,
					"longitude": 5.37606
				},
				"name": "Isadore Place",
				"created_at": "2020-07-21T05:49:37.271Z",
				"updated_at": "2020-07-25T18:29:10.112Z"
			}
		]
	}
}

Also is it possible to you to make the definitions files accessible in [@types](https://github.com/DefinitelyTyped/DefinitelyTyped) project so that the definitions could be accessible using TypeScript?

@maxusr I've released a new version on NPM that supports your issue.
Please let me any feedback if it doesn't work for you.

@maxusr I think you have missed option recursiveInArray when using snakeKeys. I've added it in this version. You can see README for the option.

Example:

jsConvert.snakeKeys(obj, { recursive: true, recursiveInArray: true });

Default, if recursive is true and recursiveInArray isn't set, recursiveInArray will be set to false.
I added this option instead of overriding the old version because I want to support other users who don't want to recursive the elements in the array. The new version is only upgraded with the new option.

About TypeScript, can you make pull request for it? Thanks a lot for it โค๏ธ