diff --git a/src/constants/enums.ts b/src/constants/enums.ts index f0a0ab6..50de53a 100644 --- a/src/constants/enums.ts +++ b/src/constants/enums.ts @@ -45,6 +45,7 @@ export enum DataTypeCategory { } export enum DataType { + IPADDRESS = "ipaddress", BIRTHDAY = "birthday", MONTH = "month", WEEKDAY = "weekday", diff --git a/src/core/generators/IpAddress/IpAddress.tsx b/src/core/generators/IpAddress/IpAddress.tsx new file mode 100644 index 0000000..37dc75c --- /dev/null +++ b/src/core/generators/IpAddress/IpAddress.tsx @@ -0,0 +1,69 @@ +import React from "react"; +import {GenerateResult, GeneratorOptionsComponentInterface} from "@/types/generator"; +import {OptionsSelect, SelectOption} from "@/components/Utils"; +import {FormattedMessage} from "@/locale"; +import {faker} from "@faker-js/faker"; +// ------------------------------------------------------------------------------------------------------------- +// types + +export type IpType = 'IPv4' | 'IPv6' + +export interface IpAddressGeneratorOptions { + types: IpType[] +} + + +// ------------------------------------------------------------------------------------------------------------- +// default options +export const IpAddressGeneratorDefaultOptions: IpAddressGeneratorOptions = { + types: ["IPv4", "IPv6"] +} + + +// ------------------------------------------------------------------------------------------------------------- +// generate method +export const generate = (options: IpAddressGeneratorOptions): GenerateResult => { + let value: string; + + if (options.types.length === 2) { + value = faker.internet.ip(); + } else if (options.types.includes("IPv4")) { + value = faker.internet.ipv4(); + } else if (options.types.includes("IPv6")){ + value = faker.internet.ipv6(); + } + + return { + value: value, + stringValue: value, + }; +} + +// ------------------------------------------------------------------------------------------------------------- +// options component +export const IpAddressGeneratorOptionsComponent: React.FunctionComponent = ({...props}) => { + const {options, handleOptionValueChange} = props as { + options: IpAddressGeneratorOptions, + handleOptionValueChange: typeof props.handleOptionValueChange + }; + + return ( +
+ } + selectOptions={IpTypeSelectOptions} + value={options.types} + onChange={(v) => handleOptionValueChange("types", v)} + style={{width: '160px'}} + /> +
+ ); +} + + +export const IpTypeSelectOptions: SelectOption[] = [ + {label: "IPv4", value: "IPv4",}, + {label: "IPv6", value: "IPv6"} +] \ No newline at end of file diff --git a/src/core/generators/IpAddress/index.ts b/src/core/generators/IpAddress/index.ts new file mode 100644 index 0000000..5fbac02 --- /dev/null +++ b/src/core/generators/IpAddress/index.ts @@ -0,0 +1,14 @@ +import {Generator} from "@/types/generator"; +import {DataType, DataTypeCategory, ValueType} from "@/constants/enums"; +import {IpAddressGeneratorDefaultOptions, IpAddressGeneratorOptionsComponent, generate} from "./IpAddress"; + +export const IpAddressGenerator: Generator = { + type: DataType.IPADDRESS, + category: DataTypeCategory.NETWORK, + generate: generate, + optionsComponent: IpAddressGeneratorOptionsComponent, + defaultOptions: IpAddressGeneratorDefaultOptions, + defaultValueType: ValueType.STRING, + exampleLines: ["245.108.222.0", "64.239.253.171", "e106:aa3c:59ac:6d0f:4c2c:bfef:86a3:62d7"] +} + \ No newline at end of file diff --git a/src/core/generators/index.ts b/src/core/generators/index.ts index 7d98b22..b490ee4 100644 --- a/src/core/generators/index.ts +++ b/src/core/generators/index.ts @@ -1,3 +1,4 @@ +import {IpAddressGenerator} from "@/core/generators/IpAddress"; import {BirthdayGenerator} from "@/core/generators/Birthday"; import {MonthGenerator} from "@/core/generators/Month"; import {WeekdayGenerator} from "@/core/generators/Weekday"; @@ -23,6 +24,7 @@ import {CompanyNameGenerator} from "@/core/generators/CompanyName"; import {DataType} from "@/constants/enums"; export const generators = { + [DataType.IPADDRESS]: IpAddressGenerator, [DataType.BIRTHDAY]: BirthdayGenerator, [DataType.MONTH]: MonthGenerator, [DataType.WEEKDAY]: WeekdayGenerator, diff --git a/src/locale/translations/en.ts b/src/locale/translations/en.ts index a298c96..e50a227 100644 --- a/src/locale/translations/en.ts +++ b/src/locale/translations/en.ts @@ -85,8 +85,10 @@ export const en = { // ------------------------------------------------------------------------------------------------------------- // data types + // ipaddress + "dataType.ipaddress": "IP Address", + "dataType.ipaddress.types":"Types", - // birthday "dataType.birthday": "Birthday", "dataType.birthday.mode":"Mode", diff --git a/src/locale/translations/jaJP.ts b/src/locale/translations/jaJP.ts index 4800825..b22809b 100644 --- a/src/locale/translations/jaJP.ts +++ b/src/locale/translations/jaJP.ts @@ -85,13 +85,9 @@ export const jaJP = { // ------------------------------------------------------------------------------------------------------------- // data types + // ipaddress + "dataType.ipaddress": "IpAddress", - - - - - - // birthday "dataType.birthday": "Birthday", diff --git a/src/locale/translations/zhCN.ts b/src/locale/translations/zhCN.ts index 7438930..b850f83 100644 --- a/src/locale/translations/zhCN.ts +++ b/src/locale/translations/zhCN.ts @@ -3,10 +3,12 @@ export const zhCN = { // export // export category + "export.category.file_types": "常见格式", "export.category.databases": "数据库", "export.category.programming_languages": "编程语言", + // export format modal "export.configurator.modal.title": "生成格式", "export.configurator.modal.confirmButton.text": "确认", @@ -83,7 +85,10 @@ export const zhCN = { // ------------------------------------------------------------------------------------------------------------- // data types - + // ipaddress + "dataType.ipaddress": "IP地址", + "dataType.ipaddress.types": "类型", + // birthday "dataType.birthday": "生日", "dataType.birthday.mode":"模式",