Skip to content

Commit

Permalink
Renaming & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
robisim74 committed May 17, 2023
1 parent 93609f4 commit 8cc08b7
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 76 deletions.
42 changes: 21 additions & 21 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"qwik-speak-extract": "./packages/qwik-speak/extract/cli.js"
},
"devDependencies": {
"@builder.io/qwik": "1.1.2",
"@builder.io/qwik-city": "1.1.2",
"@builder.io/qwik": "1.1.4",
"@builder.io/qwik-city": "1.1.4",
"@playwright/test": "^1.32.3",
"@types/eslint": "8.37.0",
"@types/node": "^18.16.1",
"@typescript-eslint/eslint-plugin": "5.59.1",
"@typescript-eslint/parser": "5.59.1",
"eslint": "8.39.0",
"eslint-plugin-qwik": "1.1.2",
"eslint-plugin-qwik": "1.1.4",
"typescript": "5.0.4",
"undici": "5.22.0",
"vite": "4.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-speak/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ module.exports = {
"prefer-const": ["error", {
"destructuring": "all"
}],
'qwik/use-method-usage': 'warn'
'qwik/use-method-usage': 'off'
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type DisplayNameFn = {
(code: string, options: Intl.DisplayNamesOptions, lang?: string): string;
};

export const useDisplayName = (
export const displayName = (
code: string,
options: Intl.DisplayNamesOptions,
lang?: string
Expand All @@ -22,5 +22,3 @@ export const useDisplayName = (

return new Intl.DisplayNames(lang, options).of(code) || code;
};

export { useDisplayName as displayName };
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type FormatDateFn = {
(value: Date | number | string, options?: Intl.DateTimeFormatOptions, lang?: string, timeZone?: string): string;
};

export const useFormatDate = (
export const formatDate = (
value: Date | number | string,
options?: Intl.DateTimeFormatOptions,
lang?: string,
Expand All @@ -31,5 +31,3 @@ export const useFormatDate = (

return new Intl.DateTimeFormat(lang, options).format(value);
};

export { useFormatDate as formatDate };
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type FormatNumberFn = {
(value: number | string, options?: Intl.NumberFormatOptions, lang?: string, currency?: string): string;
};

export const useFormatNumber = (
export const formatNumber = (
value: number | string,
options?: Intl.NumberFormatOptions,
lang?: string,
Expand All @@ -30,5 +30,3 @@ export const useFormatNumber = (

return new Intl.NumberFormat(lang, options).format(value);
};

export { useFormatNumber as formatNumber };
24 changes: 12 additions & 12 deletions packages/qwik-speak/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ export type {
} from './types';
export type { QwikSpeakProps } from './qwik-speak-component';
export type { SpeakProps } from './speak-component';
export type { TranslateFn } from './use-translate';
export type { PluralFn } from './use-plural';
export type { TranslateFn } from './translate';
export type { PluralFn } from './plural';
export type { InlineTranslateFn } from './inline-translate';
export type { FormatDateFn } from './use-format-date';
export type { FormatNumberFn } from './use-format-number';
export type { RelativeTimeFn } from './use-relative-time';
export type { DisplayNameFn } from './use-display-name';
export type { FormatDateFn } from './format-date';
export type { FormatNumberFn } from './format-number';
export type { RelativeTimeFn } from './relative-time';
export type { DisplayNameFn } from './display-name';
// Components
export { QwikSpeakProvider } from './qwik-speak-component';
export { Speak } from './speak-component';
// Functions
export { $translate } from './use-translate';
export { $plural } from './use-plural';
export { $translate } from './translate';
export { $plural } from './plural';
export { $inlineTranslate } from './inline-translate';
export { formatNumber } from './use-format-number';
export { formatDate } from './use-format-date';
export { relativeTime } from './use-relative-time';
export { displayName } from './use-display-name';
export { formatNumber } from './format-number';
export { formatDate } from './format-date';
export { relativeTime } from './relative-time';
export { displayName } from './display-name';
// Use functions
export {
useSpeakContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type PluralFn = {
lang?: string): string;
};

export const usePlural: PluralFn = (
export const $plural: PluralFn = (
value: number | string,
key?: string,
params?: Record<string, any>,
Expand All @@ -38,5 +38,3 @@ export const usePlural: PluralFn = (

return translate(key, translation[lang], { value, ...params }, config.keySeparator, config.keyValueSeparator);
};

export { usePlural as $plural };
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type RelativeTimeFn = {
): string;
};

export const useRelativeTime = (
export const relativeTime = (
value: number | string,
unit: Intl.RelativeTimeFormatUnit,
options?: Intl.RelativeTimeFormatOptions,
Expand All @@ -30,5 +30,3 @@ export const useRelativeTime = (

return new Intl.RelativeTimeFormat(lang, options).format(value, unit);
};

export { useRelativeTime as relativeTime };
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createDOM } from '@builder.io/qwik/testing';
import { component$ } from '@builder.io/qwik';
import { test, describe, expect } from 'vitest';

import { displayName as dn } from '../use-display-name';
import { displayName as dn } from '../display-name';
import { QwikSpeakProvider } from '../qwik-speak-component';
import { config } from './config';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createDOM } from '@builder.io/qwik/testing';
import { component$ } from '@builder.io/qwik';
import { test, describe, expect } from 'vitest';

import { formatDate as fd } from '../use-format-date';
import { formatDate as fd } from '../format-date';
import { QwikSpeakProvider } from '../qwik-speak-component';
import { config } from './config';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createDOM } from '@builder.io/qwik/testing';
import { component$ } from '@builder.io/qwik';
import { test, describe, expect } from 'vitest';

import { formatNumber as fn } from '../use-format-number';
import { formatNumber as fn } from '../format-number';
import { QwikSpeakProvider } from '../qwik-speak-component';
import { config } from './config';
import { useSpeakLocale } from '../use-speak';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createDOM } from '@builder.io/qwik/testing';
import { component$ } from '@builder.io/qwik';
import { test, describe, expect } from 'vitest';

import { $plural as p } from '../use-plural';
import { $plural as p } from '../plural';
import { QwikSpeakProvider } from '../qwik-speak-component';
import { config, translationFnStub } from './config';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createDOM } from '@builder.io/qwik/testing';
import { component$ } from '@builder.io/qwik';
import { test, describe, expect } from 'vitest';

import { relativeTime as rt } from '../use-relative-time';
import { relativeTime as rt } from '../relative-time';
import { QwikSpeakProvider } from '../qwik-speak-component';
import { config } from './config';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { component$ } from '@builder.io/qwik';
import { test, describe, expect } from 'vitest';

import type { Translation } from '../types';
import { $translate as t } from '../use-translate';
import { $translate as t } from '../translate';
import { QwikSpeakProvider } from '../qwik-speak-component';
import { config, translationFnStub } from './config';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ export type TranslateFn = {
<T>(keys: string[], params?: Record<string, any>, lang?: string): T[];
};

export const useTranslate: TranslateFn = (keys: string | string[], params?: Record<string, any>, lang?: string) => {
export const $translate: TranslateFn = (keys: string | string[], params?: Record<string, any>, lang?: string) => {
const ctx = useSpeakContext();
const { locale, translation, config } = ctx;

lang ??= locale.lang;

return translate(keys, translation[lang], params, config.keySeparator, config.keyValueSeparator);
}

export { useTranslate as $translate };
30 changes: 15 additions & 15 deletions packages/qwik-speak/tools/tests/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,17 @@ export const mockChunkCode = `const s_dYGb4b0cyCA = () => {
])
}, __qsInline("home.increment"), 1, null),
/* @__PURE__ */ Ar("h3", null, null, __qsInline("home.dates"), 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatDate(Date.now(), {
/* @__PURE__ */ Ar("p", null, null, formatDate(Date.now(), {
dateStyle: "full",
timeStyle: "short"
}), 1, null),
/* @__PURE__ */ Ar("p", null, null, useRelativeTime(-1, "second"), 1, null),
/* @__PURE__ */ Ar("p", null, null, relativeTime(-1, "second"), 1, null),
/* @__PURE__ */ Ar("h3", null, null, __qsInline("home.numbers"), 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatNumber(1e6), 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatNumber(1e6, {
/* @__PURE__ */ Ar("p", null, null, formatNumber(1e6), 1, null),
/* @__PURE__ */ Ar("p", null, null, formatNumber(1e6, {
style: "currency"
}), 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatNumber(1, {
/* @__PURE__ */ Ar("p", null, null, formatNumber(1, {
style: "unit",
unit: locale.units["length"]
}), 1, null)
Expand Down Expand Up @@ -326,17 +326,17 @@ export const mockInlinedCode = `const s_dYGb4b0cyCA = () => {
])
}, \`Increment\`, 1, null),
/* @__PURE__ */ Ar("h3", null, null, \`Dates & relative time\`, 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatDate(Date.now(), {
/* @__PURE__ */ Ar("p", null, null, formatDate(Date.now(), {
dateStyle: "full",
timeStyle: "short"
}), 1, null),
/* @__PURE__ */ Ar("p", null, null, useRelativeTime(-1, "second"), 1, null),
/* @__PURE__ */ Ar("p", null, null, relativeTime(-1, "second"), 1, null),
/* @__PURE__ */ Ar("h3", null, null, \`Numbers & currencies\`, 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatNumber(1e6), 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatNumber(1e6, {
/* @__PURE__ */ Ar("p", null, null, formatNumber(1e6), 1, null),
/* @__PURE__ */ Ar("p", null, null, formatNumber(1e6, {
style: "currency"
}), 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatNumber(1, {
/* @__PURE__ */ Ar("p", null, null, formatNumber(1, {
style: "unit",
unit: locale.units["length"]
}), 1, null)
Expand Down Expand Up @@ -384,17 +384,17 @@ export const mockInlinedCodeByLang = `const s_dYGb4b0cyCA = () => {
])
}, \`Incrementa\`, 1, null),
/* @__PURE__ */ Ar("h3", null, null, \`Date e tempo relativo\`, 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatDate(Date.now(), {
/* @__PURE__ */ Ar("p", null, null, formatDate(Date.now(), {
dateStyle: "full",
timeStyle: "short"
}), 1, null),
/* @__PURE__ */ Ar("p", null, null, useRelativeTime(-1, "second"), 1, null),
/* @__PURE__ */ Ar("p", null, null, relativeTime(-1, "second"), 1, null),
/* @__PURE__ */ Ar("h3", null, null, \`Numeri e valute\`, 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatNumber(1e6), 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatNumber(1e6, {
/* @__PURE__ */ Ar("p", null, null, formatNumber(1e6), 1, null),
/* @__PURE__ */ Ar("p", null, null, formatNumber(1e6, {
style: "currency"
}), 1, null),
/* @__PURE__ */ Ar("p", null, null, useFormatNumber(1, {
/* @__PURE__ */ Ar("p", null, null, formatNumber(1, {
style: "unit",
unit: locale.units["length"]
}), 1, null)
Expand Down

0 comments on commit 8cc08b7

Please sign in to comment.