Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: change to ESM #29

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [0.6.0-alpha.1](https://github.com/prismicio/prismic-mock/compare/v0.5.0...v0.6.0-alpha.1) (2024-12-16)


### Features

* add `"type": "module"` ([62ccfe5](https://github.com/prismicio/prismic-mock/commit/62ccfe50239fc3581dd0c729c42e39908c39512e))


### Refactor

* remove `change-case` dependency ([10fb86b](https://github.com/prismicio/prismic-mock/commit/10fb86b8031f617339cc03e5ab41c43d879cd584))


### Chore

* update version to latest alpha ([ba3fdc6](https://github.com/prismicio/prismic-mock/commit/ba3fdc672cd7a0716db0da1041362412be102f8e))

## [0.5.0](https://github.com/prismicio/prismic-mock/compare/v0.5.0-alpha.1...v0.5.0) (2024-12-05)

## [0.5.0-alpha.1](https://github.com/prismicio/prismic-mock/compare/v0.5.0-alpha.0...v0.5.0-alpha.1) (2024-11-28)
Expand Down
12 changes: 2 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismicio/mock",
"version": "0.5.0",
"version": "0.6.0-alpha.1",
"description": "Generate mock Prismic documents, fields, Slices, and models for development and testing environments",
"keywords": [
"typescript",
Expand All @@ -16,6 +16,7 @@
"license": "Apache-2.0",
"author": "Prismic <contact@prismic.io> (https://prismic.io)",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"require": "./dist/index.cjs",
Expand Down Expand Up @@ -58,9 +59,6 @@
"unit": "nyc --reporter=lcovonly --reporter=text --exclude-after-remap=false ava",
"unit:watch": "npm run unit -- --watch"
},
"dependencies": {
"change-case": "^5.4.4"
},
"devDependencies": {
"@prismicio/client": "7.11.0",
"@size-limit/preset-small-lib": "^11.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/api/ref.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";
import { MockRestApiConfig } from "../types";
import { timestamp } from "../value";
Expand Down Expand Up @@ -29,7 +29,7 @@ export const ref = <IsScheduled extends boolean = false>(
isMasterRef: config.isMasterRef ?? false,
label: config.isMasterRef
? "Master"
: changeCase.capitalCase(faker.words(faker.range(1, 3))),
: capitalCase(faker.words(faker.range(1, 3))),
};

if (config.isScheduled) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";
import { generateTags } from "../lib/generateTags";

Expand Down Expand Up @@ -36,7 +36,7 @@ export const repository = (
languages: [
{
id: faker.word(),
name: changeCase.capitalCase(faker.word()),
name: capitalCase(faker.word()),
is_master: true,
},
],
Expand Down
6 changes: 3 additions & 3 deletions src/lib/buildImageFieldImage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { sentenceCase } from "../lib/changeCase";
import { createFaker, Faker } from "../lib/createFaker";

import { MockValueStateConfig, MockImageData, Seed } from "../types";
Expand Down Expand Up @@ -55,8 +55,8 @@ export const buildImageFieldImage = <
id: faker.hash(11),
url: url.toString(),
dimensions,
alt: changeCase.sentenceCase(faker.words(faker.range(5, 15))),
copyright: changeCase.sentenceCase(faker.words(faker.range(5, 15))),
alt: sentenceCase(faker.words(faker.range(5, 15))),
copyright: sentenceCase(faker.words(faker.range(5, 15))),
edit: {
x: faker.range(-dimensions.width / 2, dimensions.width / 2),
y: faker.range(-dimensions.width / 2, dimensions.height / 2),
Expand Down
14 changes: 14 additions & 0 deletions src/lib/changeCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const capitalCase = (input: string) =>
stripPunctuation(input).replace(/(^\w|\s\w)/g, (char) => char.toUpperCase());

export const snakeCase = (input: string) =>
stripPunctuation(input).toLowerCase().replace(/\s/g, "_");

export const sentenceCase = (input: string) =>
stripPunctuation(input).replace(/^./, (char) => char.toUpperCase());

export const pascalCase = (input: string) =>
capitalCase(stripPunctuation(input.replace(/-|_/, " "))).replace(/ /g, "");

const stripPunctuation = (input: string) =>
input.replace(/[^\p{L}\p{N}\s]/gu, "");
5 changes: 2 additions & 3 deletions src/lib/generateCustomTypeId.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as changeCase from "change-case";

import { snakeCase } from "../lib/changeCase";
import { createFaker, Faker } from "../lib/createFaker";

import { Seed } from "../types";
Expand All @@ -17,5 +16,5 @@ type GenerateFieldIdConfig =
export const generateCustomTypeId = (config: GenerateFieldIdConfig): string => {
const faker = config.faker || createFaker(config.seed);

return changeCase.snakeCase(faker.words(faker.range(1, 3)));
return snakeCase(faker.words(faker.range(1, 3)));
};
5 changes: 2 additions & 3 deletions src/lib/generateFieldId.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as changeCase from "change-case";

import { snakeCase } from "../lib/changeCase";
import { createFaker, Faker } from "../lib/createFaker";

import { Seed } from "../types";
Expand All @@ -17,5 +16,5 @@ type GenerateFieldIdConfig =
export const generateFieldId = (config: GenerateFieldIdConfig): string => {
const faker = config.faker || createFaker(config.seed);

return changeCase.snakeCase(faker.words(faker.range(1, 3)));
return snakeCase(faker.words(faker.range(1, 3)));
};
5 changes: 2 additions & 3 deletions src/lib/generateTags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as changeCase from "change-case";

import { capitalCase } from "../lib/changeCase";
import { createFaker, Faker } from "../lib/createFaker";

import { Seed } from "../types";
Expand All @@ -23,6 +22,6 @@ export const generateTags = (config: GenerateTagsConfig): string[] => {

return Array.from(
{ length: faker.range(config.min ?? 0, config.max ?? 2) },
() => changeCase.capitalCase(faker.words(faker.range(1, 3))),
() => capitalCase(faker.words(faker.range(1, 3))),
);
};
4 changes: 2 additions & 2 deletions src/model/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand All @@ -15,7 +15,7 @@ export function boolean(
return {
type: prismic.CustomTypeModelFieldType.Boolean,
config: {
label: changeCase.capitalCase(faker.word()),
label: capitalCase(faker.word()),
},
};
}
6 changes: 3 additions & 3 deletions src/model/color.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase, sentenceCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand All @@ -15,8 +15,8 @@ export const color = (
return {
type: prismic.CustomTypeModelFieldType.Color,
config: {
label: changeCase.capitalCase(faker.word()),
placeholder: changeCase.sentenceCase(faker.words(3)),
label: capitalCase(faker.word()),
placeholder: sentenceCase(faker.words(3)),
},
};
};
6 changes: 3 additions & 3 deletions src/model/contentRelationship.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase, sentenceCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand All @@ -24,8 +24,8 @@ export const contentRelationship = <
return {
type: prismic.CustomTypeModelFieldType.Link,
config: {
label: changeCase.capitalCase(faker.word()),
placeholder: changeCase.sentenceCase(faker.words(3)),
label: capitalCase(faker.word()),
placeholder: sentenceCase(faker.words(3)),
select: prismic.CustomTypeModelLinkSelectType.Document,
customtypes: config.customTypeIDs,
tags: config.tags,
Expand Down
10 changes: 5 additions & 5 deletions src/model/customType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase, snakeCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand Down Expand Up @@ -51,13 +51,13 @@ export const customType = <
const faker = config.faker || createFaker(config.seed);

let label: string =
config.label || changeCase.capitalCase(faker.words(faker.range(1, 2)));
let id: string = config.id || changeCase.snakeCase(label);
config.label || capitalCase(faker.words(faker.range(1, 2)));
let id: string = config.id || snakeCase(label);

if (config.id && !config.label) {
label = changeCase.capitalCase(config.id);
label = capitalCase(config.id);
} else if (config.label && !config.label) {
id = changeCase.snakeCase(config.label);
id = snakeCase(config.label);
}

const format = config.format ?? faker.randomElement(["page", "custom"]);
Expand Down
6 changes: 3 additions & 3 deletions src/model/date.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase, sentenceCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand All @@ -15,8 +15,8 @@ export const date = (
return {
type: prismic.CustomTypeModelFieldType.Date,
config: {
label: changeCase.capitalCase(faker.word()),
placeholder: changeCase.sentenceCase(faker.words(3)),
label: capitalCase(faker.word()),
placeholder: sentenceCase(faker.words(3)),
},
};
};
6 changes: 3 additions & 3 deletions src/model/embed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase, sentenceCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand All @@ -15,8 +15,8 @@ export const embed = (
return {
type: prismic.CustomTypeModelFieldType.Embed,
config: {
label: changeCase.capitalCase(faker.word()),
placeholder: changeCase.sentenceCase(faker.words(3)),
label: capitalCase(faker.word()),
placeholder: sentenceCase(faker.words(3)),
},
};
};
4 changes: 2 additions & 2 deletions src/model/geoPoint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand All @@ -15,7 +15,7 @@ export const geoPoint = (
return {
type: prismic.CustomTypeModelFieldType.GeoPoint,
config: {
label: changeCase.capitalCase(faker.word()),
label: capitalCase(faker.word()),
},
};
};
4 changes: 2 additions & 2 deletions src/model/group.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { GroupFieldModelMap, MockModelConfig } from "../types";
Expand All @@ -17,7 +17,7 @@ export function group<Fields extends GroupFieldModelMap>(
return {
type: prismic.CustomTypeModelFieldType.Group,
config: {
label: changeCase.capitalCase(faker.word()),
label: capitalCase(faker.word()),
fields: config.fields || ({} as Fields),
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/model/image.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand All @@ -26,7 +26,7 @@ export const image = <ThumbnailNames extends string = string>(
return {
type: prismic.CustomTypeModelFieldType.Image,
config: {
label: changeCase.capitalCase(faker.word()),
label: capitalCase(faker.word()),
constraint: {
width: config.withConstraint ? faker.range(500, 2000) : null,
height: config.withConstraint ? faker.range(500, 2000) : null,
Expand Down
6 changes: 3 additions & 3 deletions src/model/integration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase, snakeCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand All @@ -17,8 +17,8 @@ export const integration = (
return {
type: prismic.CustomTypeModelFieldType.Integration,
config: {
label: changeCase.capitalCase(faker.word()),
catalog: config.catalog || changeCase.snakeCase(faker.words(2)),
label: capitalCase(faker.word()),
catalog: config.catalog || snakeCase(faker.words(2)),
},
};
};
6 changes: 3 additions & 3 deletions src/model/keyText.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as prismic from "@prismicio/client";
import * as changeCase from "change-case";

import { capitalCase, sentenceCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";
Expand All @@ -15,8 +15,8 @@ export const keyText = (
return {
type: prismic.CustomTypeModelFieldType.Text,
config: {
label: changeCase.capitalCase(faker.word()),
placeholder: changeCase.sentenceCase(faker.words(3)),
label: capitalCase(faker.word()),
placeholder: sentenceCase(faker.words(3)),
},
};
};
Loading
Loading