-
-
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.
Merge branch 'main' of https://github.com/codeledge/deverything into …
…add-maxCharacters-to-random-paragraph
- Loading branch information
Showing
120 changed files
with
2,359 additions
and
378 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 |
---|---|---|
|
@@ -11,3 +11,4 @@ yarn-error.log* | |
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
playground |
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
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 { PlainObject } from "../types"; | ||
import { isFunction } from "../validators"; | ||
|
||
export type PropertyAccessor<T> = keyof T | ((item: T) => any); | ||
|
||
export const getProp = <T extends PlainObject>( | ||
obj: T, | ||
propertyAccessor: PropertyAccessor<T> | ||
) => { | ||
if (isFunction(propertyAccessor)) { | ||
return propertyAccessor(obj); | ||
} | ||
|
||
return obj[propertyAccessor]; | ||
}; |
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 @@ | ||
export const loopAllChars = ( | ||
callback: (char: string, charcode: number) => void | ||
) => { | ||
let charcode = 1; | ||
let char; | ||
while (char !== "\x00") { | ||
char = String.fromCharCode(charcode); | ||
callback(char, charcode); | ||
charcode += 1; | ||
} | ||
}; |
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,28 @@ | ||
type Replacer = (this: any, key: string, value: any) => any; | ||
|
||
/** | ||
* Stringifies objects without breaking on circular dependencies | ||
* @source https://github.com/moll/json-stringify-safe/blob/master/stringify.js | ||
*/ | ||
export const objectSerializer = () => { | ||
const stack: any[] = []; | ||
const keys: string[] = []; | ||
|
||
const cycleReplacer: Replacer = function (_key, value) { | ||
if (stack[0] === value) return "[Circular ~]"; | ||
return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]"; | ||
}; | ||
|
||
return function (this: any, key: string, value: any) { | ||
if (stack.length > 0) { | ||
const thisPos = stack.indexOf(this); | ||
~thisPos ? stack.splice(thisPos + 1) : stack.push(this); | ||
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key); | ||
if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value); | ||
|
||
// TODO: also sort keys! so it can be used for deep serialization | ||
} else stack.push(value); | ||
|
||
return value; | ||
}; | ||
}; |
Oops, something went wrong.