@redocly/openapi-docs 3.12.0 → 3.12.2
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/dist/redocly-openapi-docs.min.js +753 -750
- package/lib/components/ApiInfo/ApiInfo.js +29 -1
- package/lib/components/ApiInfo/Metadata.js +29 -1
- package/lib/components/ApiInfo/index.js +2 -1
- package/lib/components/ApiInfo/styled.js +16 -8
- package/lib/components/CallbackSamples/CallbackSamples.js +25 -4
- package/lib/components/CallbackSamples/index.js +2 -1
- package/lib/components/Callbacks/CallbackDetails.js +17 -3
- package/lib/components/Callbacks/CallbackOperation.js +24 -3
- package/lib/components/Callbacks/CallbackSummary.js +19 -3
- package/lib/components/Callbacks/CallbacksList.js +16 -1
- package/lib/components/Callbacks/index.js +4 -1
- package/lib/components/Callbacks/styled.js +6 -3
- package/lib/components/Content/Content.js +10 -1
- package/lib/components/Content/index.js +2 -1
- package/lib/components/Content/useAutoScroll.js +50 -1
- package/lib/components/ContentItem/ContentItem.js +31 -1
- package/lib/components/ContentItem/index.js +2 -1
- package/lib/components/ContentItem/useIsExpanded.js +33 -1
- package/lib/components/ContentItems/ContentItems.js +19 -1
- package/lib/components/ContentItems/Items.js +13 -1
- package/lib/components/ContentItems/VirtualList.js +35 -1
- package/lib/components/ContentItems/helpers.js +49 -1
- package/lib/components/ContentItems/index.js +2 -1
- package/lib/components/ContentItems/useScrollOnRender.js +26 -1
- package/lib/components/Discriminator/Discriminator.js +27 -2
- package/lib/components/Discriminator/index.js +2 -1
- package/lib/components/Download/DownloadSpecification.js +46 -4
- package/lib/components/Download/index.js +2 -1
- package/lib/components/Download/types.js +2 -0
- package/lib/components/Download/useDownloadInfo.js +42 -1
- package/lib/components/ErrorBoundary/ErrorBoundary.js +22 -2
- package/lib/components/ErrorBoundary/index.js +2 -1
- package/lib/components/ExpandAllButton/ExpandAllButton.js +31 -2
- package/lib/components/ExpandAllButton/index.js +2 -1
- package/lib/components/ExternalDocumentation/ExternalDocumentation.js +18 -4
- package/lib/components/ExternalDocumentation/index.js +2 -1
- package/lib/components/Language/LanguageDropdown.js +21 -1
- package/lib/components/Language/LanguageItem.js +33 -1
- package/lib/components/Language/LanguageList.js +93 -1
- package/lib/components/Language/_tests_/LanguageDropdown.test.js +23 -1
- package/lib/components/Language/constants.js +3 -1
- package/lib/components/Language/index.js +4 -1
- package/lib/components/Language/styled.js +29 -15
- package/lib/components/Markdown/Markdown.js +64 -1
- package/lib/components/Markdown/index.js +3 -1
- package/lib/components/Markdown/types.js +2 -0
- package/lib/components/MediaTypeSwitch/MediaTypesSwitch.js +51 -1
- package/lib/components/MediaTypeSwitch/index.js +2 -1
- package/lib/components/OperationItem/Description.js +9 -1
- package/lib/components/OperationItem/OperationItem.js +70 -5
- package/lib/components/OperationItem/_tests_/OperationItem.test.js +70 -1
- package/lib/components/OperationItem/_tests_/__mocks__/mock-intersection-observer.js +40 -1
- package/lib/components/OperationItem/index.js +2 -1
- package/lib/components/OperationItem/types.js +2 -0
- package/lib/components/Overlay.js +48 -3
- package/lib/components/Overview/Overview.js +20 -1
- package/lib/components/Overview/index.js +2 -1
- package/lib/components/PageFooter/PageFooter.js +19 -1
- package/lib/components/PageFooter/index.js +2 -1
- package/lib/components/Panel/ResponsePanel.js +12 -6
- package/lib/components/Panel/Trigger.js +4 -2
- package/lib/components/Panel/index.js +3 -1
- package/lib/components/PanelItem/PanelItem.js +6 -1
- package/lib/components/PanelItem/index.js +3 -1
- package/lib/components/PanelItem/styled.js +20 -10
- package/lib/components/PayloadSamples/Example.js +6 -1
- package/lib/components/PayloadSamples/ExampleValue.js +30 -1
- package/lib/components/PayloadSamples/MediaTypeSamples.js +36 -2
- package/lib/components/PayloadSamples/PayloadSamples.js +26 -1
- package/lib/components/PayloadSamples/index.js +7 -1
- package/lib/components/PayloadSamples/styled.js +9 -4
- package/lib/components/PayloadSamples/types.js +2 -0
- package/lib/components/PropertyDetails/DescriptionEnums.js +19 -3
- package/lib/components/PropertyDetails/EnumValues.js +37 -1
- package/lib/components/PropertyDetails/Examples.js +26 -1
- package/lib/components/PropertyDetails/Extensions.js +17 -2
- package/lib/components/PropertyDetails/FieldDetail.js +15 -2
- package/lib/components/PropertyDetails/FieldDetails.js +51 -6
- package/lib/components/PropertyDetails/Pattern.js +21 -1
- package/lib/components/PropertyDetails/PlusCircleIcon.js +10 -4
- package/lib/components/PropertyDetails/PropertyDetails.js +22 -5
- package/lib/components/PropertyDetails/SchemaTypeInfo.js +10 -2
- package/lib/components/PropertyDetails/SimpleEnums.js +13 -2
- package/lib/components/PropertyDetails/cycleColorsByLevel.js +18 -1
- package/lib/components/PropertyDetails/index.js +4 -1
- package/lib/components/PropertyDetails/styled.js +15 -7
- package/lib/components/PropertyDetails/types.js +2 -0
- package/lib/components/RedoclyOpenAPIDocs/Providers.js +114 -1
- package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocs.js +57 -1
- package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocsStandalone.js +86 -1
- package/lib/components/RedoclyOpenAPIDocs/index.js +5 -1
- package/lib/components/RedoclyOpenAPIDocs/styled.js +4 -2
- package/lib/components/RedoclyOpenAPIDocs/types.js +2 -0
- package/lib/components/RedoclyOpenAPIDocs/utils.js +33 -1
- package/lib/components/RenderHook/RenderHook.js +17 -1
- package/lib/components/RenderHook/index.js +2 -1
- package/lib/components/Replay/EmbeddedReplay.js +41 -3
- package/lib/components/Replay/Replay.js +99 -1
- package/lib/components/Replay/index.js +3 -1
- package/lib/components/Replay/utils.js +208 -1
- package/lib/components/Request/RequestDetails.js +33 -2
- package/lib/components/Request/types.js +2 -0
- package/lib/components/RequestParameters/Body.js +8 -1
- package/lib/components/RequestParameters/ParametersGroup.js +19 -4
- package/lib/components/RequestParameters/RequestParameters.js +40 -1
- package/lib/components/RequestParameters/index.js +4 -1
- package/lib/components/RequestSamples/CodeSample.js +55 -2
- package/lib/components/RequestSamples/Example.js +37 -1
- package/lib/components/RequestSamples/RequestSamples.js +89 -5
- package/lib/components/RequestSamples/index.js +3 -1
- package/lib/components/RequestSamples/useCodeSamples.js +92 -1
- package/lib/components/ResponseSamples/ResponseSamples.js +47 -1
- package/lib/components/ResponseSamples/Summary.js +9 -1
- package/lib/components/ResponseSamples/index.js +2 -1
- package/lib/components/Responses/OperationResponseList.js +42 -2
- package/lib/components/Responses/ResponseDetails.js +18 -1
- package/lib/components/Responses/ResponseHeaders.js +15 -1
- package/lib/components/Responses/index.js +6 -1
- package/lib/components/Responses/styled.js +14 -6
- package/lib/components/Responses/types.js +2 -0
- package/lib/components/RightPanel/RightPanel.js +21 -1
- package/lib/components/RightPanel/index.js +2 -1
- package/lib/components/Samples/ExampleSwitch.js +33 -1
- package/lib/components/Samples/index.js +3 -1
- package/lib/components/Samples/use-example-key.js +12 -1
- package/lib/components/Schema/ArraySchema.js +45 -1
- package/lib/components/Schema/ObjectSchema.js +29 -1
- package/lib/components/Schema/OneOfSchema.js +47 -3
- package/lib/components/Schema/RecursiveSchema.js +10 -1
- package/lib/components/Schema/Schema.js +63 -2
- package/lib/components/Schema/SubSchema.js +20 -1
- package/lib/components/Schema/helpers.js +16 -1
- package/lib/components/Schema/index.js +5 -1
- package/lib/components/Schema/types.js +2 -0
- package/lib/components/Schema/useOneOfLocationIdx.js +11 -1
- package/lib/components/SchemaDefinition/SchemaDefinition.js +65 -2
- package/lib/components/SchemaDefinition/index.js +2 -1
- package/lib/components/SectionContent/SectionContent.js +49 -6
- package/lib/components/SectionContent/index.js +2 -1
- package/lib/components/SectionItem/SectionItem.js +14 -1
- package/lib/components/SectionItem/index.js +2 -1
- package/lib/components/Security/Divider.js +9 -2
- package/lib/components/Security/OAuthFlow.js +11 -1
- package/lib/components/Security/OAuthScopes.js +59 -9
- package/lib/components/Security/Security.js +15 -1
- package/lib/components/Security/SecurityButton.js +31 -7
- package/lib/components/Security/SecurityFlow.js +28 -4
- package/lib/components/Security/SecurityModal.js +34 -5
- package/lib/components/Security/SecuritySchemeItem.js +15 -4
- package/lib/components/Security/helper.js +16 -1
- package/lib/components/Security/index.js +11 -1
- package/lib/components/Security/styled.js +6 -3
- package/lib/components/SelectOrLabel/SelectOrLabel.js +12 -2
- package/lib/components/SelectOrLabel/index.js +2 -1
- package/lib/components/ServerList/ServerList.js +36 -10
- package/lib/components/ServerList/index.js +2 -1
- package/lib/components/ServerList/types.js +2 -0
- package/lib/components/ServerListDropdown/ServerListDropdown.js +54 -1
- package/lib/components/ServerListDropdown/index.js +2 -1
- package/lib/components/ServerListDropdown/styled.js +15 -6
- package/lib/components/SideMenu/SideMenu.js +13 -2
- package/lib/components/SideMenu/hooks/useMenuItems.js +110 -1
- package/lib/components/SideMenu/index.js +2 -1
- package/lib/components/SideMenu/types.js +2 -0
- package/lib/components/StickySidebar/SidebarActions.js +14 -2
- package/lib/components/StickySidebar/StickyResponsiveSidebar.js +37 -7
- package/lib/components/StickySidebar/index.js +2 -1
- package/lib/components/Tabs/Tabs.js +16 -5
- package/lib/components/Tabs/index.js +3 -1
- package/lib/components/Tabs/useTabsState.js +22 -1
- package/lib/components/TagItem/OperationNavigationItems.js +18 -4
- package/lib/components/TagItem/OperationsNavigation.js +46 -2
- package/lib/components/TagItem/TagItem.js +40 -7
- package/lib/components/TagItem/index.js +2 -1
- package/lib/components/TagItem/styled.js +5 -2
- package/lib/components/TagItem/types.js +2 -0
- package/lib/components/ViewNested/ViewNested.js +42 -9
- package/lib/components/ViewNested/index.js +2 -1
- package/lib/components/common/Badges.js +21 -5
- package/lib/components/common/BodyContent/BodyContent.js +31 -4
- package/lib/components/common/BodyContent/index.js +2 -1
- package/lib/components/common/ClearButton/ClearButton.js +5 -1
- package/lib/components/common/ClearButton/index.js +3 -1
- package/lib/components/common/ClearButton/styled.js +5 -2
- package/lib/components/common/ClearButton/types.js +2 -0
- package/lib/components/common/CodeBlockPanel.js +7 -3
- package/lib/components/common/ConstraintsView.js +14 -2
- package/lib/components/common/Dropdown/Dropdown.js +22 -4
- package/lib/components/common/Dropdown/index.js +2 -1
- package/lib/components/common/ExpandableExample/ExpandableExample.js +24 -3
- package/lib/components/common/ExpandableExample/index.js +2 -1
- package/lib/components/common/Extensions.js +17 -2
- package/lib/components/common/Fields/fields-layout.js +76 -51
- package/lib/components/common/Fields/fields.js +39 -17
- package/lib/components/common/Fields/index.js +3 -1
- package/lib/components/common/LinkToField.js +33 -6
- package/lib/components/common/OperationItemTitle.js +12 -6
- package/lib/components/common/SchemaSelection/SchemaSelection.js +51 -1
- package/lib/components/common/SchemaSelection/index.js +2 -1
- package/lib/components/common/Select/Select.js +21 -1
- package/lib/components/common/Select/index.js +3 -1
- package/lib/components/common/Select/styled.js +17 -9
- package/lib/components/common/Select/types.js +2 -0
- package/lib/components/common/Skeleton/LanguageListSkeleton.js +16 -6
- package/lib/components/common/Skeleton/Skeleton.js +15 -5
- package/lib/components/common/Skeleton/index.js +3 -1
- package/lib/components/common/headers.js +4 -2
- package/lib/components/common/index.js +14 -1
- package/lib/components/common/linkify.js +28 -4
- package/lib/components/common/mixins.js +4 -2
- package/lib/components/common/panels.js +52 -29
- package/lib/components/common/schema.js +16 -8
- package/lib/components/common/styled.js +15 -7
- package/lib/components/index.js +25 -1
- package/lib/components/pluggable/RedocExample.js +20 -1
- package/lib/components/pluggable/RedocSchema.js +22 -1
- package/lib/components/pluggable/index.js +3 -1
- package/lib/components/pluggable/styled.components.js +9 -4
- package/lib/constants.js +30 -1
- package/lib/empty.js +7 -1
- package/lib/events/codeSampleCopy.js +19 -1
- package/lib/events/creator.js +5 -1
- package/lib/events/index.js +8 -1
- package/lib/events/languageSwitch.js +18 -1
- package/lib/events/panelToggle.js +16 -1
- package/lib/events/serverSwitch.js +13 -1
- package/lib/events/tryItOpen.js +12 -1
- package/lib/events/tryItSent.js +12 -1
- package/lib/events/types.js +11 -1
- package/lib/hoc/types.js +2 -0
- package/lib/hoc/utils.js +4 -1
- package/lib/hoc/withRouter.js +17 -1
- package/lib/hoc/withStore.js +28 -1
- package/lib/hooks/index.js +9 -1
- package/lib/hooks/useActivateExample.js +35 -1
- package/lib/hooks/useActiveWithFallback.js +12 -1
- package/lib/hooks/useContentItems.js +10 -1
- package/lib/hooks/useLicense.js +17 -1
- package/lib/hooks/usePerformanceMetrics.js +26 -1
- package/lib/hooks/useRouter.js +17 -1
- package/lib/hooks/useTelemetry.js +5 -1
- package/lib/hooks/useTranslate.js +6 -1
- package/lib/hooks/useUppercase2LowercaseRedirect.js +12 -1
- package/lib/icons/CSharpIcon/CSharpIcon.js +7 -1
- package/lib/icons/CSharpIcon/index.js +2 -1
- package/lib/icons/CurlIcon/CurlIcon.js +8 -2
- package/lib/icons/CurlIcon/index.js +2 -1
- package/lib/icons/GOIcon/GOIcon.js +7 -1
- package/lib/icons/GOIcon/index.js +2 -1
- package/lib/icons/JavaIcon/JavaIcon.js +7 -1
- package/lib/icons/JavaIcon/index.js +2 -1
- package/lib/icons/JavaScriptIcon/JavaScriptIcon.js +7 -1
- package/lib/icons/JavaScriptIcon/index.js +2 -1
- package/lib/icons/NodeJSIcon/NodeJSIcon.js +7 -1
- package/lib/icons/NodeJSIcon/index.js +2 -1
- package/lib/icons/PHPIcon/PHPIcon.js +7 -1
- package/lib/icons/PHPIcon/index.js +2 -1
- package/lib/icons/PayloadIcon/PayloadIcon.js +7 -1
- package/lib/icons/PayloadIcon/index.js +2 -1
- package/lib/icons/PythonIcon/PythonIcon.js +7 -1
- package/lib/icons/PythonIcon/index.js +2 -1
- package/lib/icons/RIcon/RIcon.js +7 -1
- package/lib/icons/RIcon/index.js +2 -1
- package/lib/icons/RubyIcon/RubyIcon.js +7 -1
- package/lib/icons/RubyIcon/index.js +2 -1
- package/lib/index.js +49 -1
- package/lib/jotai/app.js +113 -1
- package/lib/jotai/operation.js +28 -1
- package/lib/jotai/replay.js +5 -1
- package/lib/jotai/store.js +8 -1
- package/lib/jotai/use-write-atom.js +9 -1
- package/lib/models/callback.js +28 -1
- package/lib/models/code-sample-options.js +2 -0
- package/lib/models/example.js +17 -1
- package/lib/models/field.js +109 -1
- package/lib/models/group.js +38 -1
- package/lib/models/index.js +14 -1
- package/lib/models/mediaContent.js +26 -1
- package/lib/models/mediaType.js +153 -1
- package/lib/models/operation.js +166 -1
- package/lib/models/request.js +25 -1
- package/lib/models/response.js +46 -1
- package/lib/models/schema.js +474 -2
- package/lib/models/security.js +84 -1
- package/lib/models/tab.js +2 -0
- package/lib/models/types.js +2 -0
- package/lib/services/OpenAPIParser.js +321 -1
- package/lib/services/check.js +104 -1
- package/lib/services/code-samples/constants.js +16 -1
- package/lib/services/code-samples/generator.js +540 -1
- package/lib/services/code-samples/httpsnippet/helpers/code-builder.js +252 -3
- package/lib/services/code-samples/httpsnippet/helpers/code-helpers.js +90 -2
- package/lib/services/code-samples/httpsnippet/helpers/constants.js +28 -1
- package/lib/services/code-samples/httpsnippet/helpers/lodash-int.js +173 -1
- package/lib/services/code-samples/httpsnippet/helpers/mocks/code-helpers-mock.js +76 -37
- package/lib/services/code-samples/httpsnippet/helpers/reducer.js +16 -1
- package/lib/services/code-samples/httpsnippet/helpers/shell.js +20 -1
- package/lib/services/code-samples/httpsnippet/helpers/string-utility.js +19 -1
- package/lib/services/code-samples/httpsnippet/index.js +166 -1
- package/lib/services/code-samples/httpsnippet/targets/__mocks__/mock.js +2340 -146
- package/lib/services/code-samples/httpsnippet/targets/csharp/httpclient.js +227 -2
- package/lib/services/code-samples/httpsnippet/targets/csharp/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/httpclient.js +185 -2
- package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/go/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/go/native.js +222 -3
- package/lib/services/code-samples/httpsnippet/targets/index.js +28 -1
- package/lib/services/code-samples/httpsnippet/targets/java/httpclient.js +184 -3
- package/lib/services/code-samples/httpsnippet/targets/java/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/java8/apachehttp.js +223 -2
- package/lib/services/code-samples/httpsnippet/targets/java8/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/javascript/fetch.js +147 -1
- package/lib/services/code-samples/httpsnippet/targets/javascript/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/node/fetch.js +199 -1
- package/lib/services/code-samples/httpsnippet/targets/node/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/php/curl.js +203 -5
- package/lib/services/code-samples/httpsnippet/targets/php/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/php/types.js +2 -0
- package/lib/services/code-samples/httpsnippet/targets/php/utils.js +106 -5
- package/lib/services/code-samples/httpsnippet/targets/python/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/python/requests.js +185 -6
- package/lib/services/code-samples/httpsnippet/targets/r/httr.js +111 -1
- package/lib/services/code-samples/httpsnippet/targets/r/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/r/utils.js +18 -6
- package/lib/services/code-samples/httpsnippet/targets/ruby/index.js +11 -1
- package/lib/services/code-samples/httpsnippet/targets/ruby/native.js +169 -1
- package/lib/services/code-samples/httpsnippet/targets/shell/curl.js +94 -6
- package/lib/services/code-samples/httpsnippet/targets/shell/index.js +11 -1
- package/lib/services/code-samples/index.js +3 -1
- package/lib/services/code-samples/types.js +2 -0
- package/lib/services/config-options/helpers.js +49 -1
- package/lib/services/config-options/index.js +3 -1
- package/lib/services/config-options/normalizeOptions.js +83 -1
- package/lib/services/config-options/types.js +2 -0
- package/lib/services/history/helpers.js +63 -1
- package/lib/services/history/index.js +2 -1
- package/lib/services/index.js +9 -1
- package/lib/services/menu/builder.js +47 -1
- package/lib/services/menu/index.js +2 -1
- package/lib/services/menu/markdown.js +93 -1
- package/lib/services/menu/operation.js +50 -1
- package/lib/services/menu/tags.js +166 -1
- package/lib/services/types.js +2 -0
- package/lib/services/utils.js +83 -1
- package/lib/standalone.js +68 -1
- package/lib/styled-components.js +6 -1
- package/lib/types/app.js +2 -0
- package/lib/types/index.js +4 -1
- package/lib/types/open-api.js +2 -0
- package/lib/types/security.js +2 -0
- package/lib/utils/JsonPointer.js +84 -1
- package/lib/utils/areArraysEqual.js +4 -1
- package/lib/utils/argValuesHelpers.js +35 -1
- package/lib/utils/compose.js +2 -1
- package/lib/utils/configure-helpers.js +223 -1
- package/lib/utils/convertSwagger2OpenAPI.js +14 -1
- package/lib/utils/cookies.js +73 -1
- package/lib/utils/debounce.js +22 -1
- package/lib/utils/debug.js +11 -1
- package/lib/utils/dom.js +65 -1
- package/lib/utils/environments.js +13 -1
- package/lib/utils/helpers.js +222 -12
- package/lib/utils/index.js +25 -1
- package/lib/utils/isMobile.js +13 -1
- package/lib/utils/loadAndBundleSpec.js +32 -1
- package/lib/utils/local-storage.js +12 -1
- package/lib/utils/object.js +31 -1
- package/lib/utils/openapi.js +592 -1
- package/lib/utils/parameters.js +13 -1
- package/lib/utils/path.js +22 -1
- package/lib/utils/queryString.js +60 -1
- package/lib/utils/replaceVariables.js +14 -1
- package/lib/utils/saveTextBeforeHeading.js +35 -1
- package/lib/utils/security-details.js +49 -1
- package/lib/utils/session-storage.js +12 -1
- package/lib/utils/simplifyAstStructure.js +22 -1
- package/lib/utils/sort.js +21 -1
- package/lib/utils/string.js +65 -1
- package/lib/utils/telemetry.js +7 -1
- package/lib/utils/test-utils.js +26 -1
- package/lib/utils/theme-helpers.js +24 -3
- package/lib/utils/url.js +38 -1
- package/package.json +4 -4
|
@@ -1,3 +1,252 @@
|
|
|
1
|
-
import*as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as util from 'util';
|
|
2
|
+
import { Lang, NamingVariableConventions, VariableType } from './constants.js';
|
|
3
|
+
import StringUtility from './string-utility.js';
|
|
4
|
+
const langToVarNameConvention = {
|
|
5
|
+
[Lang.NODEJS]: NamingVariableConventions.CAMEL_CASE,
|
|
6
|
+
[Lang.JAVASCRIPT]: NamingVariableConventions.CAMEL_CASE,
|
|
7
|
+
[Lang.PYTHON]: NamingVariableConventions.UNDER_SCORES,
|
|
8
|
+
[Lang.JAVA8]: NamingVariableConventions.CAMEL_CASE,
|
|
9
|
+
[Lang.JAVA]: NamingVariableConventions.CAMEL_CASE,
|
|
10
|
+
[Lang.CSHARP]: NamingVariableConventions.PASCAL_CASE,
|
|
11
|
+
[Lang.CSHARPNEWTONSOFT]: NamingVariableConventions.PASCAL_CASE,
|
|
12
|
+
[Lang.CURL]: NamingVariableConventions.CAMEL_CASE,
|
|
13
|
+
[Lang.GO]: NamingVariableConventions.CAMEL_CASE,
|
|
14
|
+
[Lang.PHP]: NamingVariableConventions.CAMEL_CASE,
|
|
15
|
+
[Lang.RUBY]: NamingVariableConventions.UNDER_SCORES,
|
|
16
|
+
[Lang.R]: NamingVariableConventions.UNDER_SCORES,
|
|
17
|
+
};
|
|
18
|
+
const langOptions = {
|
|
19
|
+
default: {
|
|
20
|
+
joinSymbol: '',
|
|
21
|
+
variableWrapperFn: (v) => v,
|
|
22
|
+
stringLiteral: (t) => t,
|
|
23
|
+
variableDeclaration: (n) => n,
|
|
24
|
+
urlFieldName: 'url',
|
|
25
|
+
},
|
|
26
|
+
[Lang.CSHARP]: {
|
|
27
|
+
joinSymbol: ' + ',
|
|
28
|
+
stringLiteral: (t) => `"${t}"`,
|
|
29
|
+
variableDeclaration: (n) => `var ${n} = %s;`,
|
|
30
|
+
urlFieldName: 'fullUrl',
|
|
31
|
+
},
|
|
32
|
+
[Lang.CSHARPNEWTONSOFT]: {
|
|
33
|
+
joinSymbol: ' + ',
|
|
34
|
+
stringLiteral: (t) => `"${t}"`,
|
|
35
|
+
variableDeclaration: (n) => `var ${n} = %s;`,
|
|
36
|
+
urlFieldName: 'fullUrl',
|
|
37
|
+
},
|
|
38
|
+
[Lang.GO]: {
|
|
39
|
+
joinSymbol: ' + ',
|
|
40
|
+
stringLiteral: (t) => `"${t}"`,
|
|
41
|
+
variableDeclaration: (n) => `${n} := %s;`,
|
|
42
|
+
},
|
|
43
|
+
[Lang.JAVA]: {
|
|
44
|
+
joinSymbol: ' + ',
|
|
45
|
+
stringLiteral: (t) => `"${t}"`,
|
|
46
|
+
variableDeclaration: (n) => `var ${n} = %s;`,
|
|
47
|
+
urlFieldName: 'pathname',
|
|
48
|
+
},
|
|
49
|
+
[Lang.JAVA8]: {
|
|
50
|
+
joinSymbol: ' + ',
|
|
51
|
+
stringLiteral: (t) => `"${t}"`,
|
|
52
|
+
variableDeclaration: (n) => `String ${n} = %s;`,
|
|
53
|
+
urlFieldName: 'fullUrl',
|
|
54
|
+
},
|
|
55
|
+
[Lang.JAVASCRIPT]: {
|
|
56
|
+
variableWrapperFn: (v) => '${' + v + '}',
|
|
57
|
+
variableDeclaration: (n, options) => `const ${n} = ${options?.hasVariableInterpolation ? '`%s`' : "'%s'"};`,
|
|
58
|
+
},
|
|
59
|
+
[Lang.NODEJS]: {
|
|
60
|
+
variableWrapperFn: (v) => '${' + v + '}',
|
|
61
|
+
variableDeclaration: (n, options) => `const ${n} = ${options?.hasVariableInterpolation ? '`%s`' : "'%s'"};`,
|
|
62
|
+
},
|
|
63
|
+
[Lang.PHP]: {
|
|
64
|
+
joinSymbol: ' . ',
|
|
65
|
+
stringLiteral: (t) => `"${t}"`,
|
|
66
|
+
variableDeclaration: (n) => `const ${n} = %s;`,
|
|
67
|
+
},
|
|
68
|
+
[Lang.PYTHON]: {
|
|
69
|
+
stringLiteral: (t) => `"${t}"`,
|
|
70
|
+
joinSymbol: ' + ',
|
|
71
|
+
variableDeclaration: (n) => `${n} = %s`,
|
|
72
|
+
},
|
|
73
|
+
[Lang.RUBY]: {
|
|
74
|
+
joinSymbol: ' + ',
|
|
75
|
+
stringLiteral: (t) => `'${t}'`,
|
|
76
|
+
variableDeclaration: (n) => `${n} = %s`,
|
|
77
|
+
},
|
|
78
|
+
[Lang.CURL]: {
|
|
79
|
+
variableWrapperFn: (name, value) => value || `{${name}}`,
|
|
80
|
+
urlFieldName: 'fullUrl',
|
|
81
|
+
rawName: true,
|
|
82
|
+
},
|
|
83
|
+
[Lang.R]: {
|
|
84
|
+
joinSymbol: ' %&% ',
|
|
85
|
+
variableDeclaration: (n) => `${n} = %s`,
|
|
86
|
+
urlFieldName: 'fullUrl',
|
|
87
|
+
stringLiteral: (t) => `"${t}"`,
|
|
88
|
+
variableWrapperFn: (name) => `${name}`,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
const reservedVariableNames = [
|
|
92
|
+
'response',
|
|
93
|
+
'request',
|
|
94
|
+
'requests',
|
|
95
|
+
'data',
|
|
96
|
+
'url',
|
|
97
|
+
'payload',
|
|
98
|
+
'main',
|
|
99
|
+
'accessToken',
|
|
100
|
+
'resp',
|
|
101
|
+
'Program',
|
|
102
|
+
'client',
|
|
103
|
+
'postData',
|
|
104
|
+
'App',
|
|
105
|
+
'httpClient',
|
|
106
|
+
'params',
|
|
107
|
+
'pathname',
|
|
108
|
+
'host',
|
|
109
|
+
'body',
|
|
110
|
+
'fetch',
|
|
111
|
+
'query',
|
|
112
|
+
];
|
|
113
|
+
/**
|
|
114
|
+
* Helper object to format and aggragate lines of code.
|
|
115
|
+
* Lines are aggregated in a `code` array, and need to be joined to obtain a proper code snippet.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} indentation Desired indentation character for aggregated lines of code
|
|
118
|
+
* @param {string} lineJoin Desired character to join each line of code
|
|
119
|
+
*/
|
|
120
|
+
export class CodeBuilder {
|
|
121
|
+
code;
|
|
122
|
+
indentation;
|
|
123
|
+
variablesPrefix;
|
|
124
|
+
lineJoin;
|
|
125
|
+
capitalize;
|
|
126
|
+
lang;
|
|
127
|
+
langOptions;
|
|
128
|
+
constructor({ indentation, lineJoin = '\n', variablesPrefix = '', capitalize = false, lang = Lang.CURL, }) {
|
|
129
|
+
this.code = [];
|
|
130
|
+
this.indentation = indentation;
|
|
131
|
+
this.variablesPrefix = variablesPrefix;
|
|
132
|
+
this.lineJoin = lineJoin || '\n';
|
|
133
|
+
this.capitalize = capitalize;
|
|
134
|
+
this.lang = lang;
|
|
135
|
+
this.langOptions = {
|
|
136
|
+
...langOptions.default,
|
|
137
|
+
...langOptions[lang],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Add given indentation level to given string and format the string (variadic)
|
|
142
|
+
* @param {number} [indentationLevel=0] - Desired level of indentation for this line
|
|
143
|
+
* @param {string} line - Line of code. Can contain formatting placeholders
|
|
144
|
+
* @param rest
|
|
145
|
+
* @param {...object} - Parameter to bind to `line`'s formatting placeholders
|
|
146
|
+
* @return {string}
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* const builder = CodeBuilder('\t')
|
|
150
|
+
*
|
|
151
|
+
* builder.buildLine('console.log("hello world")')
|
|
152
|
+
* // returns: 'console.log("hello world")'
|
|
153
|
+
*
|
|
154
|
+
* builder.buildLine(2, 'console.log("hello world")')
|
|
155
|
+
* // returns: 'console.log("\t\thello world")'
|
|
156
|
+
*
|
|
157
|
+
* builder.buildLine(2, 'console.log("%s %s")', 'hello', 'world')
|
|
158
|
+
* // returns: 'console.log("\t\thello world")'
|
|
159
|
+
*/
|
|
160
|
+
buildLine(indentationLevel, line) {
|
|
161
|
+
let lineIndentation = '';
|
|
162
|
+
let slice = 2;
|
|
163
|
+
if (typeof indentationLevel === 'string') {
|
|
164
|
+
slice = 1;
|
|
165
|
+
line = indentationLevel;
|
|
166
|
+
indentationLevel = 0;
|
|
167
|
+
}
|
|
168
|
+
else if (indentationLevel === null) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
while (indentationLevel) {
|
|
172
|
+
lineIndentation += this.indentation;
|
|
173
|
+
indentationLevel--;
|
|
174
|
+
}
|
|
175
|
+
// eslint-disable-next-line prefer-rest-params
|
|
176
|
+
const format = Array.prototype.slice.call(arguments, slice, arguments.length);
|
|
177
|
+
format.unshift(lineIndentation + line);
|
|
178
|
+
return util.format.apply(this, format);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Invoke buildLine() and add the line at the top of current lines
|
|
182
|
+
* @return {this}
|
|
183
|
+
* @param args
|
|
184
|
+
*/
|
|
185
|
+
unshift(...args) {
|
|
186
|
+
// @ts-ignore
|
|
187
|
+
// eslint-disable-next-line prefer-spread
|
|
188
|
+
this.code.unshift(this.buildLine.apply(this, args));
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Invoke buildLine() and add the line at the bottom of current lines
|
|
193
|
+
* @return {this}
|
|
194
|
+
* @param args
|
|
195
|
+
*/
|
|
196
|
+
push(...args) {
|
|
197
|
+
// @ts-ignore
|
|
198
|
+
// eslint-disable-next-line prefer-spread
|
|
199
|
+
this.code.push(this.buildLine.apply(this, args));
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Add an empty line at the end of current lines
|
|
204
|
+
* @return {this}
|
|
205
|
+
*/
|
|
206
|
+
blank() {
|
|
207
|
+
this.code.push(null);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Concatenate all current lines using the given lineJoin
|
|
212
|
+
* @return {string}
|
|
213
|
+
*/
|
|
214
|
+
join() {
|
|
215
|
+
return this.code.join(this.lineJoin);
|
|
216
|
+
}
|
|
217
|
+
clean() {
|
|
218
|
+
this.code.splice(1);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Get variable name, use variablesPrefix if specified
|
|
222
|
+
* @param {string} name
|
|
223
|
+
* @param {VariableType} type
|
|
224
|
+
* @return {string}
|
|
225
|
+
*/
|
|
226
|
+
var(name, type = VariableType.CUSTOM) {
|
|
227
|
+
if (type === VariableType.PATH) {
|
|
228
|
+
let value = this.variablesPrefix + name;
|
|
229
|
+
if (reservedVariableNames.includes(value)) {
|
|
230
|
+
value = `${value}_path`;
|
|
231
|
+
}
|
|
232
|
+
switch (langToVarNameConvention[this.lang]) {
|
|
233
|
+
case NamingVariableConventions.UNDER_SCORES:
|
|
234
|
+
value = StringUtility.toSnakeCase(value);
|
|
235
|
+
break;
|
|
236
|
+
case NamingVariableConventions.PASCAL_CASE:
|
|
237
|
+
value = StringUtility.toPascalCase(value);
|
|
238
|
+
break;
|
|
239
|
+
case NamingVariableConventions.CAMEL_CASE:
|
|
240
|
+
default:
|
|
241
|
+
value = StringUtility.toCamelCase(value);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
246
|
+
// TODO remove, once we refactor all variables in code-samples
|
|
247
|
+
return this.variablesPrefix
|
|
248
|
+
? this.variablesPrefix + (this.capitalize ? StringUtility.toPascalCase(name) : name)
|
|
249
|
+
: name;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=code-builder.js.map
|
|
@@ -1,2 +1,90 @@
|
|
|
1
|
-
import{VariableType
|
|
2
|
-
|
|
1
|
+
import { VariableType } from './constants.js';
|
|
2
|
+
export function getPreserveTransformer({ body, authorizationHeader, }) {
|
|
3
|
+
return function (input, prop, originalResult) {
|
|
4
|
+
if (body) {
|
|
5
|
+
// Keep original body without extra stringifying (assume that body already stringified)
|
|
6
|
+
if (prop === 'body' && typeof input.body === 'string') {
|
|
7
|
+
return input.body;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
if (authorizationHeader) {
|
|
11
|
+
// Keep original Authorization header without stringifying (for basic auth code)
|
|
12
|
+
if (prop === 'Authorization' && typeof input.Authorization === 'string') {
|
|
13
|
+
return input.Authorization;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return originalResult;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function addIndentation(str, { level = 0, indent = ' ', firstLine = true } = {}) {
|
|
20
|
+
const indentation = indent.repeat(level);
|
|
21
|
+
// TODO: keep original indentaion type
|
|
22
|
+
const strWithExtraIndentation = str.replace(/(\r\n|\n|\r)/gm, `\n${indentation}`);
|
|
23
|
+
if (firstLine) {
|
|
24
|
+
return indentation.concat(strWithExtraIndentation);
|
|
25
|
+
}
|
|
26
|
+
return strWithExtraIndentation;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parse url with arguments into concatenation operands array so it can be manipulated easily language-independently
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // returns [{type: 'string', value: '/var/'}, {type: 'variable', name: 'test'}, {type: "string", value: "/"}]
|
|
33
|
+
* parseUrlIntoOperands("/url/:test/", {test: 1})
|
|
34
|
+
**/
|
|
35
|
+
export function parseUrlIntoOperands(url, params) {
|
|
36
|
+
const paramNames = Object.keys(params);
|
|
37
|
+
const paramNamesInOrder = paramNames
|
|
38
|
+
.map((name) => ({ name, idx: url.indexOf(`{${name}}`) }))
|
|
39
|
+
.filter(({ idx }) => idx > -1) // filter out unused
|
|
40
|
+
.sort((a, b) => a.idx - b.idx);
|
|
41
|
+
const operands = [];
|
|
42
|
+
let prevIdx = 0;
|
|
43
|
+
for (const { name, idx } of paramNamesInOrder) {
|
|
44
|
+
if (idx > prevIdx) {
|
|
45
|
+
operands.push({ type: 'string', value: url.substring(prevIdx, idx) });
|
|
46
|
+
}
|
|
47
|
+
operands.push({ type: 'variable', name });
|
|
48
|
+
prevIdx = idx + name.length + 2; // 2 for curly braces
|
|
49
|
+
}
|
|
50
|
+
if (prevIdx < url.length)
|
|
51
|
+
operands.push({ type: 'string', value: url.substring(prevIdx) });
|
|
52
|
+
return operands;
|
|
53
|
+
}
|
|
54
|
+
export function buildUrlExpression(source, code, url) {
|
|
55
|
+
const { joinSymbol, variableWrapperFn, stringLiteral, urlFieldName, rawName } = code.langOptions;
|
|
56
|
+
const { pathParameters = {}, serverVariables = {} } = source;
|
|
57
|
+
const variablesData = { ...pathParameters, ...serverVariables };
|
|
58
|
+
return parseUrlIntoOperands(url ?? source[urlFieldName] ?? '', variablesData)
|
|
59
|
+
.map((operand) => {
|
|
60
|
+
if (operand.type === 'variable') {
|
|
61
|
+
const variableValue = variablesData[operand.name];
|
|
62
|
+
const variableName = rawName ? operand.name : code.var(operand.name, VariableType.PATH);
|
|
63
|
+
return variableWrapperFn(variableName, variableValue);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// string
|
|
67
|
+
return stringLiteral(operand.value);
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
.join(joinSymbol);
|
|
71
|
+
}
|
|
72
|
+
export function printUrlVariablesDeclarations(source, code, indentationLevel) {
|
|
73
|
+
const variablesData = { ...source.pathParameters, ...source.serverVariables };
|
|
74
|
+
Object.entries(variablesData).forEach(([key, value]) => {
|
|
75
|
+
if (key === 'server')
|
|
76
|
+
return; // special case for environment variable called server
|
|
77
|
+
const variableValue = value || `YOUR_${key}_PARAMETER`;
|
|
78
|
+
const variableName = code.var(key, VariableType.PATH);
|
|
79
|
+
const operands = parseUrlIntoOperands(variableValue, variablesData);
|
|
80
|
+
const hasVariableInterpolation = operands.some((operand) => operand.type === 'variable');
|
|
81
|
+
const expression = buildUrlExpression(source, code, variableValue);
|
|
82
|
+
if (indentationLevel !== undefined) {
|
|
83
|
+
code.push(indentationLevel, code.langOptions.variableDeclaration(variableName, { hasVariableInterpolation }), expression);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
code.push(code.langOptions.variableDeclaration(variableName, { hasVariableInterpolation }), expression);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=code-helpers.js.map
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
export var Lang;
|
|
2
|
+
(function (Lang) {
|
|
3
|
+
Lang["NODEJS"] = "Node.js";
|
|
4
|
+
Lang["JAVASCRIPT"] = "javascript";
|
|
5
|
+
Lang["PYTHON"] = "Python";
|
|
6
|
+
Lang["JAVA8"] = "Java8+Apache";
|
|
7
|
+
Lang["JAVA"] = "Java";
|
|
8
|
+
Lang["CSHARP"] = "C#";
|
|
9
|
+
Lang["CSHARPNEWTONSOFT"] = "C#+Newtonsoft";
|
|
10
|
+
Lang["CURL"] = "curl";
|
|
11
|
+
Lang["GO"] = "Go";
|
|
12
|
+
Lang["PHP"] = "PHP";
|
|
13
|
+
Lang["RUBY"] = "Ruby";
|
|
14
|
+
Lang["R"] = "R";
|
|
15
|
+
})(Lang || (Lang = {}));
|
|
16
|
+
export var NamingVariableConventions;
|
|
17
|
+
(function (NamingVariableConventions) {
|
|
18
|
+
NamingVariableConventions["UNDER_SCORES"] = "under_scores";
|
|
19
|
+
NamingVariableConventions["CAMEL_CASE"] = "camelCase";
|
|
20
|
+
NamingVariableConventions["PASCAL_CASE"] = "PascalCase";
|
|
21
|
+
})(NamingVariableConventions || (NamingVariableConventions = {}));
|
|
22
|
+
export var VariableType;
|
|
23
|
+
(function (VariableType) {
|
|
24
|
+
VariableType["IMPORT"] = "import";
|
|
25
|
+
VariableType["CUSTOM"] = "custom";
|
|
26
|
+
VariableType["PATH"] = "path";
|
|
27
|
+
})(VariableType || (VariableType = {}));
|
|
28
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1,173 @@
|
|
|
1
|
-
|
|
1
|
+
/* Functions in this file are copied from lodash */
|
|
2
|
+
/** Used to compose unicode character classes. */
|
|
3
|
+
const rsAstralRange = '\\ud800-\\udfff';
|
|
4
|
+
const rsComboMarksRange = '\\u0300-\\u036f';
|
|
5
|
+
const reComboHalfMarksRange = '\\ufe20-\\ufe2f';
|
|
6
|
+
const rsComboSymbolsRange = '\\u20d0-\\u20ff';
|
|
7
|
+
const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff';
|
|
8
|
+
const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff';
|
|
9
|
+
const rsComboRange = rsComboMarksRange +
|
|
10
|
+
reComboHalfMarksRange +
|
|
11
|
+
rsComboSymbolsRange +
|
|
12
|
+
rsComboMarksExtendedRange +
|
|
13
|
+
rsComboMarksSupplementRange;
|
|
14
|
+
const rsDingbatRange = '\\u2700-\\u27bf';
|
|
15
|
+
const rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff';
|
|
16
|
+
const rsMathOpRange = '\\xac\\xb1\\xd7\\xf7';
|
|
17
|
+
const rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf';
|
|
18
|
+
const rsPunctuationRange = '\\u2000-\\u206f';
|
|
19
|
+
const rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000';
|
|
20
|
+
const rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde';
|
|
21
|
+
const rsVarRange = '\\ufe0e\\ufe0f';
|
|
22
|
+
const rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
|
|
23
|
+
const reQuotes = /['\u2019]/g;
|
|
24
|
+
/** Used to compose unicode capture groups. */
|
|
25
|
+
const rsApos = "['\u2019]";
|
|
26
|
+
const rsBreak = `[${rsBreakRange}]`;
|
|
27
|
+
const rsCombo = `[${rsComboRange}]`;
|
|
28
|
+
const rsDigit = '\\d';
|
|
29
|
+
const rsDingbat = `[${rsDingbatRange}]`;
|
|
30
|
+
const rsLower = `[${rsLowerRange}]`;
|
|
31
|
+
const rsMisc = `[^${rsAstralRange}${rsBreakRange + rsDigit + rsDingbatRange + rsLowerRange + rsUpperRange}]`;
|
|
32
|
+
const rsFitz = '\\ud83c[\\udffb-\\udfff]';
|
|
33
|
+
const rsModifier = `(?:${rsCombo}|${rsFitz})`;
|
|
34
|
+
const rsNonAstral = `[^${rsAstralRange}]`;
|
|
35
|
+
const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
|
|
36
|
+
const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
|
|
37
|
+
const rsUpper = `[${rsUpperRange}]`;
|
|
38
|
+
const rsZWJ = '\\u200d';
|
|
39
|
+
/** Used to compose unicode regexes. */
|
|
40
|
+
const rsMiscLower = `(?:${rsLower}|${rsMisc})`;
|
|
41
|
+
const rsMiscUpper = `(?:${rsUpper}|${rsMisc})`;
|
|
42
|
+
const rsOptContrLower = `(?:${rsApos}(?:d|ll|m|re|s|t|ve))?`;
|
|
43
|
+
const rsOptContrUpper = `(?:${rsApos}(?:D|LL|M|RE|S|T|VE))?`;
|
|
44
|
+
const reOptMod = `${rsModifier}?`;
|
|
45
|
+
const rsOptVar = `[${rsVarRange}]?`;
|
|
46
|
+
const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*`;
|
|
47
|
+
const rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])';
|
|
48
|
+
const rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])';
|
|
49
|
+
const rsSeq = rsOptVar + reOptMod + rsOptJoin;
|
|
50
|
+
const rsEmoji = `(?:${[rsDingbat, rsRegional, rsSurrPair].join('|')})${rsSeq}`;
|
|
51
|
+
const reUnicodeWords = RegExp(
|
|
52
|
+
// eslint-disable-next-line no-misleading-character-class
|
|
53
|
+
[
|
|
54
|
+
`${rsUpper}?${rsLower}+${rsOptContrLower}(?=${[rsBreak, rsUpper, '$'].join('|')})`,
|
|
55
|
+
`${rsMiscUpper}+${rsOptContrUpper}(?=${[rsBreak, rsUpper + rsMiscLower, '$'].join('|')})`,
|
|
56
|
+
`${rsUpper}?${rsMiscLower}+${rsOptContrLower}`,
|
|
57
|
+
`${rsUpper}+${rsOptContrUpper}`,
|
|
58
|
+
rsOrdUpper,
|
|
59
|
+
rsOrdLower,
|
|
60
|
+
`${rsDigit}+`,
|
|
61
|
+
rsEmoji,
|
|
62
|
+
].join('|'), 'g');
|
|
63
|
+
const unicodeWords = (string) => string.match(reUnicodeWords);
|
|
64
|
+
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
|
|
65
|
+
// eslint-disable-next-line no-misleading-character-class
|
|
66
|
+
const reHasUnicode = RegExp(`[${rsZWJ + rsAstralRange + rsComboRange + rsVarRange}]`);
|
|
67
|
+
/**
|
|
68
|
+
* Checks if `string` contains Unicode symbols.
|
|
69
|
+
*
|
|
70
|
+
* @private
|
|
71
|
+
* @param {string} string The string to inspect.
|
|
72
|
+
* @returns {boolean} Returns `true` if a symbol is found, else `false`.
|
|
73
|
+
*/
|
|
74
|
+
const hasUnicode = (string) => reHasUnicode.test(string);
|
|
75
|
+
/** Used to compose unicode capture groups. */
|
|
76
|
+
const rsAstral = `[${rsAstralRange}]`;
|
|
77
|
+
const rsNonAstralCombo = `${rsNonAstral}${rsCombo}?`;
|
|
78
|
+
const rsSymbol = `(?:${[rsNonAstralCombo, rsCombo, rsRegional, rsSurrPair, rsAstral].join('|')})`;
|
|
79
|
+
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
|
|
80
|
+
// eslint-disable-next-line no-misleading-character-class
|
|
81
|
+
const reUnicode = RegExp(`${rsFitz}(?=${rsFitz})|${rsSymbol + rsSeq}`, 'g');
|
|
82
|
+
const unicodeToArray = (string) => string.match(reUnicode) || [];
|
|
83
|
+
const asciiToArray = (string) => string.split('');
|
|
84
|
+
const getTag = (value) => {
|
|
85
|
+
const toString = Object.prototype.toString;
|
|
86
|
+
if (value == null) {
|
|
87
|
+
return value === undefined ? '[object Undefined]' : '[object Null]';
|
|
88
|
+
}
|
|
89
|
+
return toString.call(value);
|
|
90
|
+
};
|
|
91
|
+
const isSymbol = (value) => {
|
|
92
|
+
const type = typeof value;
|
|
93
|
+
return (type == 'symbol' || (type === 'object' && value != null && getTag(value) == '[object Symbol]'));
|
|
94
|
+
};
|
|
95
|
+
/** Used as references for various `Number` constants. */
|
|
96
|
+
const INFINITY = 1 / 0;
|
|
97
|
+
const toString = (value) => {
|
|
98
|
+
if (value == null) {
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
// Exit early for strings to avoid a performance hit in some environments.
|
|
102
|
+
if (typeof value === 'string') {
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
if (Array.isArray(value)) {
|
|
106
|
+
// Recursively convert values (susceptible to call stack limits).
|
|
107
|
+
return `${value.map((other) => (other == null ? other : toString(other)))}`;
|
|
108
|
+
}
|
|
109
|
+
if (isSymbol(value)) {
|
|
110
|
+
return value.toString();
|
|
111
|
+
}
|
|
112
|
+
const result = `${value}`;
|
|
113
|
+
return result == '0' && 1 / value == -INFINITY ? '-0' : result;
|
|
114
|
+
};
|
|
115
|
+
const hasUnicodeWord = RegExp.prototype.test.bind(/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/);
|
|
116
|
+
/** Used to match words composed of alphanumeric characters. */
|
|
117
|
+
// eslint-disable-next-line no-control-regex
|
|
118
|
+
const reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|
119
|
+
const asciiWords = (string) => string.match(reAsciiWord);
|
|
120
|
+
const slice = (array, start, end) => {
|
|
121
|
+
let length = array == null ? 0 : array.length;
|
|
122
|
+
if (!length) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
start = start == null ? 0 : start;
|
|
126
|
+
end = end === undefined ? length : end;
|
|
127
|
+
if (start < 0) {
|
|
128
|
+
start = -start > length ? 0 : length + start;
|
|
129
|
+
}
|
|
130
|
+
end = end > length ? length : end;
|
|
131
|
+
if (end < 0) {
|
|
132
|
+
end += length;
|
|
133
|
+
}
|
|
134
|
+
length = start > end ? 0 : (end - start) >>> 0;
|
|
135
|
+
start >>>= 0;
|
|
136
|
+
let index = -1;
|
|
137
|
+
const result = new Array(length);
|
|
138
|
+
while (++index < length) {
|
|
139
|
+
result[index] = array[index + start];
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
};
|
|
143
|
+
const words = (string) => {
|
|
144
|
+
const result = hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
|
|
145
|
+
return result || [];
|
|
146
|
+
};
|
|
147
|
+
const castSlice = (array, start) => {
|
|
148
|
+
const { length } = array;
|
|
149
|
+
const end = length;
|
|
150
|
+
return !start && end >= length ? array : slice(array, start, end);
|
|
151
|
+
};
|
|
152
|
+
const stringToArray = (string) => hasUnicode(string) ? unicodeToArray(string) : asciiToArray(string);
|
|
153
|
+
const createCaseFirst = (methodName) => {
|
|
154
|
+
return (string) => {
|
|
155
|
+
if (!string) {
|
|
156
|
+
return '';
|
|
157
|
+
}
|
|
158
|
+
const strSymbols = hasUnicode(string) ? stringToArray(string) : undefined;
|
|
159
|
+
const chr = strSymbols ? strSymbols[0] : string[0];
|
|
160
|
+
const trailing = strSymbols ? castSlice(strSymbols, 1).join('') : string.slice(1);
|
|
161
|
+
return chr[methodName]() + trailing;
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
const upperFirst = createCaseFirst('toUpperCase');
|
|
165
|
+
const camelCase = (string) => words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => {
|
|
166
|
+
word = word.toLowerCase();
|
|
167
|
+
return result + (index ? upperFirst(word) : word);
|
|
168
|
+
}, '');
|
|
169
|
+
const lowerCase = (string) => words(toString(string).replace(reQuotes, '')).reduce((result, word, index) => result + (index ? ' ' : '') + word.toLowerCase(), '');
|
|
170
|
+
const snakeCase = (string) => words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? '_' : '') + word.toLowerCase(), '');
|
|
171
|
+
const startCase = (string) => words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? ' ' : '') + upperFirst(word), '');
|
|
172
|
+
export { camelCase, lowerCase, snakeCase, startCase };
|
|
173
|
+
//# sourceMappingURL=lodash-int.js.map
|