-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also: * Move logos to a central location * Make the loading spinner color-scheme-aware * Recreate `OverviewPageHeader`, `HomeIcon`, `HeaderLogo`, `SolutionTitle`, `Welcome`, `Overview` tests * Enhance `ExitFullScreenButton`, `Header` tests * Tinified favicon assets Signed-off-by: Miki <[email protected]>
- Loading branch information
Showing
102 changed files
with
3,658 additions
and
8,008 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
packages/osd-dev-utils/src/serializers/flat_object_serializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Any modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
const walk = (value: any, path: string[] = [], collector: string[] = []) => { | ||
let objValue; | ||
switch (Object.prototype.toString.call(value)) { | ||
case '[object Map]': | ||
case '[object WeakMap]': | ||
objValue = Object.fromEntries(value); | ||
break; | ||
|
||
case '[object Set]': | ||
case '[object WeakSet]': | ||
objValue = Array.from(value); | ||
break; | ||
|
||
case '[object Object]': | ||
case '[object Array]': | ||
objValue = value; | ||
break; | ||
|
||
case '[object RegExp]': | ||
case '[object Function]': | ||
case '[object Date]': | ||
case '[object Boolean]': | ||
case '[object Number]': | ||
case '[object Symbol]': | ||
case '[object Error]': | ||
collector.push(`${path.join('.')} = ${value.toString()}`); | ||
break; | ||
|
||
case '[object Null]': | ||
collector.push(`${path.join('.')} = null`); | ||
break; | ||
|
||
case '[object Undefined]': | ||
collector.push(`${path.join('.')} = undefined`); | ||
break; | ||
|
||
case '[object String]': | ||
collector.push(`${path.join('.')} = ${JSON.stringify(value)}`); | ||
break; | ||
|
||
case '[object BigInt]': | ||
collector.push(`${path.join('.')} = ${value.toString()}n`); | ||
break; | ||
|
||
default: | ||
if (value instanceof Object.getPrototypeOf(Uint8Array)) { | ||
objValue = Array.from(value); | ||
} | ||
} | ||
|
||
if (!objValue) return collector; | ||
|
||
if (Array.isArray(objValue)) { | ||
objValue.forEach((v, i) => { | ||
walk(v, [...path, i.toString()], collector); | ||
}); | ||
} else { | ||
// eslint-disable-next-line guard-for-in | ||
for (const key in objValue) { | ||
walk(objValue[key], [...path, key], collector); | ||
} | ||
} | ||
|
||
return collector; | ||
}; | ||
export const flatObjectSerializer = { | ||
test: (value: any) => | ||
['[object Object]', '[object Array]'].includes(Object.prototype.toString.call(value)), | ||
serialize: (value: any) => walk(value).sort().join('\n'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './logos'; |
Oops, something went wrong.