refactor: Use named exports instead of default exports (#2238)

* use named exports instead of default exports

* fix tests

Co-authored-by: Philipp Kühn <philippkuehn@MacBook-Pro-von-Philipp.local>
This commit is contained in:
Philipp Kühn
2021-12-06 12:00:09 +01:00
committed by GitHub
parent fa8318c38f
commit e07a5b625d
123 changed files with 279 additions and 283 deletions

View File

@@ -1,5 +1,5 @@
import { MaybeReturnType } from '../types'
import isFunction from './isFunction'
import { isFunction } from './isFunction'
/**
* Optionally calls `value` as a function.
@@ -8,7 +8,7 @@ import isFunction from './isFunction'
* @param context Optional context to bind to function.
* @param props Optional props to pass to function.
*/
export default function callOrReturn<T>(value: T, context: any = undefined, ...props: any[]): MaybeReturnType<T> {
export function callOrReturn<T>(value: T, context: any = undefined, ...props: any[]): MaybeReturnType<T> {
if (isFunction(value)) {
if (context) {
return value.bind(context)(...props)

View File

@@ -1,4 +1,4 @@
export default function createStyleTag(style: string): HTMLStyleElement {
export function createStyleTag(style: string): HTMLStyleElement {
const tipTapStyleTag = (<HTMLStyleElement>document.querySelector('style[data-tiptap-style]'))
if (tipTapStyleTag !== null) {

View File

@@ -3,7 +3,7 @@
* @param obj Object
* @param key Key to remove
*/
export default function deleteProps(obj: Record<string, any>, propOrProps: string | string[]): Record<string, any> {
export function deleteProps(obj: Record<string, any>, propOrProps: string | string[]): Record<string, any> {
const props = typeof propOrProps === 'string'
? [propOrProps]
: propOrProps

View File

@@ -1,4 +1,4 @@
export default function elementFromString(value: string): HTMLElement {
export function elementFromString(value: string): HTMLElement {
// add a wrapper to preserve leading and trailing whitespace
const wrappedValue = `<body>${value}</body>`

View File

@@ -1,4 +1,4 @@
export default function findDuplicates(items: any[]): any[] {
export function findDuplicates(items: any[]): any[] {
const filtered = items.filter((el, index) => items.indexOf(el) !== index)
return [...new Set(filtered)]

View File

@@ -1,4 +1,4 @@
export default function fromString(value: any): any {
export function fromString(value: any): any {
if (typeof value !== 'string') {
return value
}

View File

@@ -1,4 +1,4 @@
export default function isClass(value: any): boolean {
export function isClass(value: any): boolean {
if (value.constructor?.toString().substring(0, 5) !== 'class') {
return false
}

View File

@@ -1,3 +1,3 @@
export default function isEmptyObject(value = {}): boolean {
export function isEmptyObject(value = {}): boolean {
return Object.keys(value).length === 0 && value.constructor === Object
}

View File

@@ -1,3 +1,3 @@
export default function isObject(value: any): value is Function {
export function isFunction(value: any): value is Function {
return typeof value === 'function'
}

View File

@@ -1,3 +1,3 @@
export default function isNumber(value: any): value is number {
export function isNumber(value: any): value is number {
return typeof value === 'number'
}

View File

@@ -1,6 +1,6 @@
import isClass from './isClass'
import { isClass } from './isClass'
export default function isObject(value: any): boolean {
export function isObject(value: any): boolean {
return (
value
&& typeof value === 'object'

View File

@@ -4,7 +4,7 @@ function getType(value: any): string {
return Object.prototype.toString.call(value).slice(8, -1)
}
export default function isPlainObject(value: any): value is Record<string, any> {
export function isPlainObject(value: any): value is Record<string, any> {
if (getType(value) !== 'Object') {
return false
}

View File

@@ -1,3 +1,3 @@
export default function isRegExp(value: any): value is RegExp {
export function isRegExp(value: any): value is RegExp {
return Object.prototype.toString.call(value) === '[object RegExp]'
}

View File

@@ -1,3 +1,3 @@
export default function isString(value: any): value is string {
export function isString(value: any): value is string {
return typeof value === 'string'
}

View File

@@ -1,4 +1,4 @@
export default function isiOS(): boolean {
export function isiOS(): boolean {
return [
'iPad Simulator',
'iPhone Simulator',

View File

@@ -1,4 +1,4 @@
export default function mergeAttributes(...objects: Record<string, any>[]): Record<string, any> {
export function mergeAttributes(...objects: Record<string, any>[]): Record<string, any> {
return objects
.filter(item => !!item)
.reduce((items, item) => {

View File

@@ -1,6 +1,6 @@
import isPlainObject from './isPlainObject'
import { isPlainObject } from './isPlainObject'
export default function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any> {
export function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any> {
const output = { ...target }
if (isPlainObject(target) && isPlainObject(source)) {

View File

@@ -1,3 +1,3 @@
export default function minMax(value = 0, min = 0, max = 0): number {
export function minMax(value = 0, min = 0, max = 0): number {
return Math.min(Math.max(value, min), max)
}

View File

@@ -1,11 +1,11 @@
import isRegExp from './isRegExp'
import { isRegExp } from './isRegExp'
/**
* Check if object1 includes object2
* @param object1 Object
* @param object2 Object
*/
export default function objectIncludes(
export function objectIncludes(
object1: Record<string, any>,
object2: Record<string, any>,
options: { strict: boolean } = { strict: true },

View File

@@ -2,7 +2,7 @@
* Removes duplicated values within an array.
* Supports numbers, strings and objects.
*/
export default function removeDuplicates<T>(array: T[], by = JSON.stringify): T[] {
export function removeDuplicates<T>(array: T[], by = JSON.stringify): T[] {
const seen: Record<any, any> = {}
return array.filter(item => {