Skip to content

Commit

Permalink
Added ponyfills for modern js features
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianhelvikspond committed Feb 12, 2024
1 parent 7af6e96 commit 4c41422
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
21 changes: 19 additions & 2 deletions samples/client/echo_api/typescript-axios/build/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
21 changes: 19 additions & 2 deletions samples/client/petstore/typescript-axios/builds/default/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,33 @@ function convertMapsAndSetsToPlain(value: any): any {
return Array.from(value).map(item => convertMapsAndSetsToPlain(item));
}
if (value instanceof Map) {
return Object.fromEntries([...value.entries()]
return objectFromEntries([...value.entries()]
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}
if (Array.isArray(value)) {
return value.map(it => convertMapsAndSetsToPlain(it));
}
return Object.fromEntries(Object.entries(value)
return objectFromEntries(objectEntries(value)
.map(([k, v]) => [k, convertMapsAndSetsToPlain(v)]));
}

/**
* Ponyfill for Object.entries
*/
function objectEntries(object: Record<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Loading

0 comments on commit 4c41422

Please sign in to comment.