Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
fix: don't use module (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta authored Sep 21, 2023
1 parent a685083 commit b457c36
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions src/lib/style-formatting/style-serializer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable import/no-import-module-exports */
/* eslint-disable no-param-reassign */
import type { Merge } from 'type-fest';

Expand Down Expand Up @@ -28,30 +27,6 @@ function isObject(value: unknown) {
return typeof value === 'object' && value !== null;
}

export interface StylizerConfig {
escape: boolean | 'unsafe';
explode: boolean;
isAllowedReserved?: boolean;
key: string;
location: 'body' | 'query';
style: 'deepObject' | 'form' | 'label' | 'matrix' | 'pipeDelimited' | 'simple' | 'spaceDelimited';
value: any;
}

export default function stylize(config: StylizerConfig) {
const { value } = config;

if (Array.isArray(value)) {
return encodeArray(config);
}

if (isObject(value)) {
return encodeObject(config);
}

return encodePrimitive(config);
}

export function encodeDisallowedCharacters(
str: string,
// eslint-disable-next-line @typescript-eslint/default-param-last
Expand Down Expand Up @@ -112,6 +87,30 @@ export function encodeDisallowedCharacters(
.join('');
}

export interface StylizerConfig {
escape: boolean | 'unsafe';
explode: boolean;
isAllowedReserved?: boolean;
key: string;
location: 'body' | 'query';
style: 'deepObject' | 'form' | 'label' | 'matrix' | 'pipeDelimited' | 'simple' | 'spaceDelimited';
value: any;
}

export default function stylize(config: StylizerConfig) {
const { value } = config;

if (Array.isArray(value)) {
return encodeArray(config);
}

if (isObject(value)) {
return encodeObject(config);
}

return encodePrimitive(config);
}

/**
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-examples}
*/
Expand All @@ -125,7 +124,7 @@ function encodeArray({
isAllowedReserved = false,
}: Merge<StylizerConfig, { value: string[] }>) {
const valueEncoder = (str: string) =>
module.exports.encodeDisallowedCharacters(str, {
encodeDisallowedCharacters(str, {
escape,
returnIfEncoded: location === 'query',
isAllowedReserved,
Expand Down Expand Up @@ -197,7 +196,7 @@ function encodeArray({
*/
function encodeObject({ location, key, value, style, explode, escape, isAllowedReserved = false }: StylizerConfig) {
const valueEncoder = (str: string) =>
module.exports.encodeDisallowedCharacters(str, {
encodeDisallowedCharacters(str, {
escape,
returnIfEncoded: location === 'query',
isAllowedReserved,
Expand Down Expand Up @@ -322,7 +321,7 @@ function encodeObject({ location, key, value, style, explode, escape, isAllowedR
*/
function encodePrimitive({ location, key, value, style, escape, isAllowedReserved = false }: StylizerConfig) {
const valueEncoder = (str: string) =>
module.exports.encodeDisallowedCharacters(str, {
encodeDisallowedCharacters(str, {
escape,
returnIfEncoded: location === 'query' || location === 'body',
isAllowedReserved,
Expand Down

0 comments on commit b457c36

Please sign in to comment.