Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/codeledge/deverything into …
Browse files Browse the repository at this point in the history
…add-maxCharacters-to-random-paragraph
  • Loading branch information
narcis-fv committed Sep 28, 2023
2 parents 52f6154 + a4c48d8 commit 18a1292
Show file tree
Hide file tree
Showing 120 changed files with 2,359 additions and 378 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ yarn-error.log*
.env.development.local
.env.test.local
.env.production.local
playground
146 changes: 145 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,154 @@
# deverything

## 0.28.1

### Patch Changes

- fix random pw

## 0.28.0

### Minor Changes

- company and phone number

## 0.27.1

### Patch Changes

- guard bool

## 0.27.0

### Minor Changes

- add math

## 0.26.0

### Minor Changes

- serializeObject

## 0.25.2

### Patch Changes

- addresses

## 0.25.1

### Patch Changes

- clamping

## 0.25.0

### Minor Changes

- normalize

## 0.24.0

### Minor Changes

- shuffle

## 0.23.1

### Patch Changes

- add direct val

## 0.23.0

### Minor Changes

- checks

## 0.22.3

### Patch Changes

- more nouns

## 0.22.2

### Patch Changes

- percentage and dates

## 0.22.1

### Patch Changes

- random date fix

## 0.22.0

### Minor Changes

- enums

## 0.21.2

### Patch Changes

- missing exports

## 0.21.1

### Patch Changes

- fix pretty

## 0.21.0

### Minor Changes

- Added moveToIndex helper function

## 0.20.0

### Minor Changes

- bank accounts

## 0.19.2

### Patch Changes

- clean spaces pro

## 0.19.1

### Patch Changes

- consts

## 0.19.0

### Minor Changes

- fixes and object firsts

## 0.18.0

### Minor Changes

- add diffs

## 0.17.1

### Patch Changes

- capitalize

## 0.17.0

### Minor Changes

- Updated randomParagraph to have the maxCharacters and words variables
- added promiseWithTimeout() function with test and readme entry

## 0.16.0

Expand Down
46 changes: 36 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Contributions always welcome!
- `isJsDate()` if it's a **valid** javascript's Date
- `isFutureDate()`
- `isPastDate()`
- `isTimestamp()`
- `isStringDate()` also checks if the string passed is a **valid** date
- `isKey()` is a real key of an object
- `isLastIndex()` is the index is the last item of array
- `isNumber()` if the arg is number, and also usable (no infinity)
- `isInt()`
- `isEven()`
Expand All @@ -43,14 +43,24 @@ Contributions always welcome!
- `isPWA()`
- `isReactElement()`
- `isRegExp()`
-`isSame()` Compare if dates, functions, arrays, objects or anything else are the same
- `isServer()` if you are on the server
- `isString()`
- `isURL()`
- `isUUID()`

### Math

- `average()`
- `max()`
- `min()`
- `sum()`

### Helpers

- `array()` create an arbitrary array based on a function
- `arrayDiff()`
- `arrayIntersection()`
- `capitalize()` word => Word
- `cleanSpaces()` trims and turns double spaces into single space
- `clamp()` clamp number in a range
Expand All @@ -59,12 +69,18 @@ Contributions always welcome!
- `last()` get the last element of an array
-`merge()` deep merge objects
- `moveToFirst()` move array element to first
- `moveToIndex()` move array element to desired index
- `moveToLast()` move array element to last
- `normalizeNumber()` normalizes between 0 and 1
- `objectDiff()`
-`parseDate()` pass anything Date-Like, and get a JS Date back
- `pretty()`
- `sleep()`
- `toggleArray()`
- `pretty()` stringify anything, without breaking on circular dependencies
- `promiseWithTimeout()` takes a promise, a timeoutMs, and an option error as arguments. Returns a new Promise that either resolves with the value of the input promise or rejects with the provided error or a default error message if the input promise does not resolve or reject within the specified timeoutMs.
- `sleep()` promise-based sleep
- `shuffle()` shuffles elements in an array
- `toggleArrayValue()` remove/add value in array
- `truncate()` truncate text, does not break emojis
- `uniqueValues()` gets unique values in an array

### Random data generators

Expand All @@ -73,7 +89,9 @@ These functions are optimized for low entropy random data generation useful for
- `randomAddress()`
- `randomAlphaNumericCode()`
-`randomArrayItem()`
- `randomBankAccount()`
- `randomBool()`
- `randomCompany()`
-`randomCoords()`
- `randomLat()`
- `randomLng()`
Expand Down Expand Up @@ -107,23 +125,31 @@ These functions are optimized for low entropy random data generation useful for
- `randomNumericId()` autoincremental process-unique id
- `randomParagraph()`
- `randomPassword()`
- `randomPhoneNumber()`
- `randomUUID()` lightweight uuid generation, passing UUID validation
- `randomWord()`

### Checks

Checks are functions that throw an error, if the validation fails

-`checkEnvVars()` Make sure env vars are set per-environment

### TypeScript Helpers

- `Coords`
- `DateLike`
- `Dimensions`
- `Maybe`
- `MaybePromise`
- `MaybePromiseOrValue`
- `MaybePromiseOrValueArray`
- `Maybe<>`
- `MaybePromise<>`
- `MaybePromiseOrValue<>`
- `MaybePromiseOrValueArray<>`
- `NonUndefined`
- `ObjectValues`
- `ObjectKey<>`
- `ObjectValue<>`
- `PlainObject`
- `Point`
- `PrismaSelect`
- `PrismaSelect<>`

## Development

Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "deverything",
"version": "0.17.0",
"version": "0.28.1",
"description": "Everything you need for Dev",
"main": "dist/index.js",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"sideEffects": false,
Expand All @@ -24,18 +24,19 @@
"url": "git+https://github.com/codeledge/deverything.git"
},
"keywords": [
"random",
"generator",
"checks",
"dates",
"fake",
"testing",
"validators",
"generator",
"helpers",
"toolkit",
"words",
"numbers",
"dates",
"random",
"testing",
"toolkit",
"types",
"utils"
"utils",
"validators",
"words"
],
"author": "ogroppo",
"license": "MIT",
Expand Down
15 changes: 15 additions & 0 deletions src/_internals/getProp.ts
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];
};
11 changes: 11 additions & 0 deletions src/_internals/loopAllChars.ts
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;
}
};
28 changes: 28 additions & 0 deletions src/_internals/objectSerializer.ts
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;
};
};
Loading

0 comments on commit 18a1292

Please sign in to comment.