-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more formatters, types and validators
- Loading branch information
Showing
19 changed files
with
129 additions
and
23 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# deverything | ||
|
||
## 0.44.0 | ||
|
||
### Minor Changes | ||
|
||
- randomObject isFile and many more | ||
|
||
## 0.43.0 | ||
|
||
### Minor Changes | ||
|
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
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,7 @@ | ||
export const formatCamelCase = (str: string) => { | ||
return str | ||
.toLowerCase() | ||
.replace(/[-_\s]([a-z\d])(\w*)/g, function replacer(_m, p1, p2) { | ||
return p1.toUpperCase() + p2; | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./formatCamelCase"; | ||
export * from "./formatNumber"; | ||
export * from "./stringToUnicode"; | ||
export * from "./stringToCSSUnicode"; | ||
export * from "./stringToUnicode"; |
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,9 @@ | ||
import { describe, it, expect } from "@jest/globals"; | ||
import { keysLength } from "../helpers"; | ||
import { randomObject } from "./randomObject"; | ||
|
||
describe(`randomObject`, () => { | ||
it(`works`, () => { | ||
expect(keysLength(randomObject())).toBeGreaterThan(0); | ||
}); | ||
}); |
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,19 @@ | ||
import { array } from "../helpers"; | ||
import { PlainObject } from "../types"; | ||
import { randomInt } from "./randomInt"; | ||
import { randomValue } from "./randomValue"; | ||
import { randomNoun } from "./randomWord"; | ||
|
||
export const randomObject = ({ maxDepth = 5 }: { maxDepth?: number } = {}) => { | ||
const getRandomObject = (depth: number): PlainObject => { | ||
if (depth >= maxDepth) return {}; | ||
|
||
const keys = array(randomInt(1, 5), randomNoun); | ||
return keys.reduce((partial, key) => { | ||
partial[key] = randomValue() || getRandomObject(depth + 1); | ||
return partial; | ||
}, {} as PlainObject); | ||
}; | ||
|
||
return getRandomObject(0); | ||
}; |
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,16 @@ | ||
import { randomArrayItem } from "./randomArrayItem"; | ||
import { randomBool } from "./randomBool"; | ||
import { randomDate } from "./randomDate"; | ||
import { randomInt } from "./randomInt"; | ||
import { randomString } from "./randomString"; | ||
|
||
export const randomValue = () => { | ||
return randomArrayItem([ | ||
randomBool(), | ||
randomString(), | ||
randomInt(), | ||
randomDate(), | ||
undefined, | ||
null, | ||
]); | ||
}; |
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 @@ | ||
export type VoidFn = () => void; |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { Key } from "./Object"; | ||
|
||
// I don't like the Dict keyword, but it's a possibility... | ||
export type HashMapKey = string | number | symbol; | ||
export type HashMap<T> = Record<HashMapKey, T>; | ||
export type NumberMap = Record<HashMapKey, number>; | ||
export type StringMap = Record<HashMapKey, string>; | ||
export type BoolMap = Record<HashMapKey, boolean>; | ||
export type TrueMap = Record<HashMapKey, true>; | ||
export type HashMap<T> = Record<Key, T>; | ||
export type NumberMap = Record<Key, number>; | ||
export type StringMap = Record<Key, string>; | ||
export type BoolMap = Record<Key, boolean>; | ||
export type TrueMap = Record<Key, true>; |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export type Key = string | number | symbol; | ||
export type ObjectKey<T> = keyof T; | ||
export type ObjectKeys<T> = ObjectKey<T>[]; | ||
export type ObjectValue<T> = T[keyof T]; | ||
export type ObjectValues<T> = ObjectValue<T>[]; | ||
// ObjectEntry needed? | ||
export type ObjectEntries<T> = { [K in keyof T]: [K, T[K]] }[keyof T][]; | ||
export type ObjectEntry<T> = { [K in keyof T]: [K, T[K]] }[keyof T]; | ||
export type ObjectEntries<T> = ObjectEntry<T>[]; |
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 |
---|---|---|
@@ -1 +1,9 @@ | ||
export type PlainObject = Record<string | symbol, any> & { length?: never }; // Excludes arrays | ||
import { Key } from "./Object"; | ||
|
||
/** | ||
* A plain object is an object that is not an array, does not have a length property, and is not a function. | ||
* Would have been nice to call it just Object, but that's already taken by the built-in type. | ||
*/ | ||
export type PlainObject<T = any> = Record<Key, T> & { | ||
length?: never; | ||
}; // Excludes arrays |
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,15 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { isBuffer } from "./isBuffer"; | ||
|
||
describe("isBuffer", () => { | ||
test("mixed", async () => { | ||
const buffer = Buffer.from("test"); | ||
expect(isBuffer(buffer)).toBe(true); | ||
|
||
const arraybuffer = new Uint8Array([1, 2, 3]).buffer; | ||
expect(isBuffer(arraybuffer)).toBe(false); | ||
|
||
const notBuffer = { byteLength: 3, slice: () => {} }; | ||
expect(isBuffer(notBuffer)).toBe(false); | ||
}); | ||
}); |
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,11 @@ | ||
import { isFunction } from "./isFunction"; | ||
import { isValue } from "./isValue"; | ||
|
||
export const isBuffer = (val?: any): boolean => { | ||
return ( | ||
isValue(val) && | ||
isValue(val.constructor) && | ||
isFunction(val.constructor.isBuffer) && | ||
val.constructor.isBuffer(val) | ||
); | ||
}; |
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,2 @@ | ||
export const isFile = (arg?: any): arg is File => | ||
Object.prototype.toString.call(arg) === "[object File]"; |
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
export const isKey = <T extends object>( | ||
key: string | number | symbol, | ||
obj: T | ||
): key is keyof T => | ||
import { Key } from "../types/Object"; | ||
|
||
export const isKey = <T extends object>(key: Key, obj: T): key is keyof T => | ||
obj.hasOwnProperty(key) && // makes sure the prop is not in the prototype chain | ||
obj.propertyIsEnumerable(key); // makes sure the prop is not a getter/setter |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export const isObject = <T>(arg?: any): arg is Record<string, T> => | ||
import { PlainObject } from "../types"; | ||
|
||
export const isObject = <T>(arg?: any): arg is PlainObject<T> => | ||
Object.prototype.toString.call(arg) === "[object Object]"; |