From a95793cffcd5d5d60c650469176f81e0e7a66a07 Mon Sep 17 00:00:00 2001 From: Mateus Abelli Date: Sat, 22 Apr 2023 18:02:06 -0300 Subject: [PATCH 1/2] Implement library structure --- api/api.csproj | 4 + api/{ => src}/Program.cs | 10 +- cli/nuget.config | 1 + cli/src/CliManager.cs | 120 ----- cli/src/Generate.cs | 16 - cli/src/Program.cs | 120 ++++- cli/src/Validate.cs | 16 - cli/valid-ip.csproj | 4 + lib/dotnet/.gitignore | 454 ++++++++++++++++++ {library => lib/dotnet}/LICENSE.md | 0 lib/dotnet/README.md | 3 + lib/dotnet/ValidIp.csproj | 9 + lib/dotnet/nuget.config | 8 + lib/dotnet/src/Generate.cs | 16 + lib/dotnet/src/Validate.cs | 16 + {library => lib/nodejs}/.gitignore | 0 lib/nodejs/LICENSE.md | 21 + lib/nodejs/README.md | 62 +++ {library => lib/nodejs}/jsconfig.json | 0 {library => lib/nodejs}/package.json | 0 {library => lib/nodejs}/pnpm-lock.yaml | 0 {library => lib/nodejs}/src/index.js | 0 .../nodejs}/src/test/index.test.js | 0 {library => lib/nodejs}/src/types/index.d.ts | 0 library/README.md | 3 - 25 files changed, 720 insertions(+), 163 deletions(-) rename api/{ => src}/Program.cs (73%) delete mode 100644 cli/src/CliManager.cs delete mode 100644 cli/src/Generate.cs delete mode 100644 cli/src/Validate.cs create mode 100644 lib/dotnet/.gitignore rename {library => lib/dotnet}/LICENSE.md (100%) create mode 100644 lib/dotnet/README.md create mode 100644 lib/dotnet/ValidIp.csproj create mode 100644 lib/dotnet/nuget.config create mode 100644 lib/dotnet/src/Generate.cs create mode 100644 lib/dotnet/src/Validate.cs rename {library => lib/nodejs}/.gitignore (100%) create mode 100644 lib/nodejs/LICENSE.md create mode 100644 lib/nodejs/README.md rename {library => lib/nodejs}/jsconfig.json (100%) rename {library => lib/nodejs}/package.json (100%) rename {library => lib/nodejs}/pnpm-lock.yaml (100%) rename {library => lib/nodejs}/src/index.js (100%) rename {library => lib/nodejs}/src/test/index.test.js (100%) rename {library => lib/nodejs}/src/types/index.d.ts (100%) delete mode 100644 library/README.md diff --git a/api/api.csproj b/api/api.csproj index c78c9c7..6bdcb69 100644 --- a/api/api.csproj +++ b/api/api.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/api/Program.cs b/api/src/Program.cs similarity index 73% rename from api/Program.cs rename to api/src/Program.cs index 1a9ae92..87a00f8 100644 --- a/api/Program.cs +++ b/api/src/Program.cs @@ -1,4 +1,4 @@ -namespace api; +using ValidIp; public class Program { @@ -10,25 +10,25 @@ public static void Main(string[] args) app.MapGet("/validate/ipv4/{ip}", (string ip) => { // TODO - return $"Validating... {ip} IPv4"; + return Validate.IpV4(ip); }); app.MapGet("/validate/ipv6/{ip}", (string ip) => { // TODO - return $"Validating... {ip} IPv6"; + return Validate.IpV6(ip); }); app.MapGet("/generate/ipv4/{generateAmount}", (int generateAmount) => { // TODO - return $"Generating... {generateAmount} x ipV4"; + return Generate.IpV4(generateAmount); }); app.MapGet("/generate/ipv6/{generateAmount}", (int generateAmount) => { // TODO - return $"Generating... {generateAmount} x ipV6"; + return Generate.IpV6(generateAmount); }); app.Run(); diff --git a/cli/nuget.config b/cli/nuget.config index 6ce9759..c9e284e 100644 --- a/cli/nuget.config +++ b/cli/nuget.config @@ -4,5 +4,6 @@ + diff --git a/cli/src/CliManager.cs b/cli/src/CliManager.cs deleted file mode 100644 index 695a9e6..0000000 --- a/cli/src/CliManager.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System.CommandLine; - -namespace ValidIp; - -class CliManager { - public static int ParseArgs(string[] args) - { - var isV4Option = new Option( - name: "--v4", - description: "Test if is a valid IPv4" - ); - - var isV6Option = new Option( - name: "--v6", - description: "Test if is a valid IPv6" - ); - - isV4Option.ArgumentHelpName = "ip"; - isV6Option.ArgumentHelpName = "ip"; - - var rootCommand = new RootCommand( - "Validate or generate random IP addresses.\n" - + "Example usage: valid-ip --v4 8.8.8.8" - ); - - rootCommand.AddOption(isV4Option); - rootCommand.AddOption(isV6Option); - - rootCommand.AddValidator(result => - { - if ( - result.FindResultFor(isV4Option) is not null - && result.FindResultFor(isV6Option) is not null - ) - { - result.ErrorMessage = "You cannot use options --v4 and --v6 together"; - } - }); - - rootCommand.SetHandler( - (ipV4, ipV6) => - { - if (ipV4 is not null) - { - Validate.IpV4(ipV4); - return; - } - - if (ipV6 is not null) - { - Validate.IpV6(ipV6); - return; - } - else - rootCommand.Invoke("--help"); - }, - isV4Option, - isV6Option - ); - - var generateV4Option = new Option( - name: "--v4", - description: "Generate of IPv4 addresses" - ); - - var generateV6Option = new Option( - name: "--v6", - description: "Generate of IPv6 addresses" - ); - - generateV4Option.ArgumentHelpName = "amount"; - generateV6Option.ArgumentHelpName = "amount"; - - var generateCommand = new Command( - name: "generate", - description: "Generate random IP addresses.\n" - + "Example usage: valid-ip generate --v4 8" - ); - - generateCommand.AddOption(generateV4Option); - generateCommand.AddOption(generateV6Option); - - generateCommand.AddAlias("gen"); - - rootCommand.AddCommand(generateCommand); - - generateCommand.AddValidator(result => - { - if (result.FindResultFor(generateV4Option) is not null - && result.FindResultFor(generateV6Option) is not null) - { - result.ErrorMessage = "You cannot use options --v4 and --v6 together"; - } - }); - - generateCommand.SetHandler( - (ipV4Amount, ipV6Amount) => - { - if (ipV4Amount is not 0) - { - Generate.IpV4(ipV4Amount); - return; - } - - if (ipV6Amount is not 0) - { - Generate.IpV6(ipV6Amount); - return; - } - else - generateCommand.Invoke("--help"); - }, - generateV4Option, - generateV6Option - ); - - return rootCommand.Invoke(args); - - } -} \ No newline at end of file diff --git a/cli/src/Generate.cs b/cli/src/Generate.cs deleted file mode 100644 index f3d2e72..0000000 --- a/cli/src/Generate.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace ValidIp; - -class Generate -{ - public static void IpV4(int generateAmount) - { - // TODO - Console.WriteLine($"Generating... {generateAmount} x ipV4"); - } - - public static void IpV6(int generateAmount) - { - // TODO - Console.WriteLine($"Generating... {generateAmount} x ipV6"); - } -} \ No newline at end of file diff --git a/cli/src/Program.cs b/cli/src/Program.cs index 8d8a4a6..88663ac 100644 --- a/cli/src/Program.cs +++ b/cli/src/Program.cs @@ -1,9 +1,123 @@ -namespace ValidIp; +using System.CommandLine; +using ValidIp; class Program { - static void Main(string[] args) + static int Main(string[] args) { - CliManager.ParseArgs(args); + var isV4Option = new Option( + name: "--v4", + description: "Test if is a valid IPv4" + ); + + var isV6Option = new Option( + name: "--v6", + description: "Test if is a valid IPv6" + ); + + isV4Option.ArgumentHelpName = "ip"; + isV6Option.ArgumentHelpName = "ip"; + + var rootCommand = new RootCommand( + "Validate or generate random IP addresses.\n" + + "Example usage: valid-ip --v4 8.8.8.8" + ); + + rootCommand.AddOption(isV4Option); + rootCommand.AddOption(isV6Option); + + rootCommand.AddValidator(result => + { + if ( + result.FindResultFor(isV4Option) is not null + && result.FindResultFor(isV6Option) is not null + ) + { + result.ErrorMessage = "You cannot use options --v4 and --v6 together"; + } + }); + + rootCommand.SetHandler( + (ipV4, ipV6) => + { + if (ipV4 is not null) + { + var result = Validate.IpV4(ipV4); + Console.WriteLine(result); + return; + } + + if (ipV6 is not null) + { + var result = Validate.IpV6(ipV6); + Console.WriteLine(result); + return; + } + else + rootCommand.Invoke("--help"); + }, + isV4Option, + isV6Option + ); + + var generateV4Option = new Option( + name: "--v4", + description: "Generate of IPv4 addresses" + ); + + var generateV6Option = new Option( + name: "--v6", + description: "Generate of IPv6 addresses" + ); + + generateV4Option.ArgumentHelpName = "amount"; + generateV6Option.ArgumentHelpName = "amount"; + + var generateCommand = new Command( + name: "generate", + description: "Generate random IP addresses.\n" + + "Example usage: valid-ip generate --v4 8" + ); + + generateCommand.AddOption(generateV4Option); + generateCommand.AddOption(generateV6Option); + + generateCommand.AddAlias("gen"); + + rootCommand.AddCommand(generateCommand); + + generateCommand.AddValidator(result => + { + if (result.FindResultFor(generateV4Option) is not null + && result.FindResultFor(generateV6Option) is not null) + { + result.ErrorMessage = "You cannot use options --v4 and --v6 together"; + } + }); + + generateCommand.SetHandler( + (ipV4Amount, ipV6Amount) => + { + if (ipV4Amount is not 0) + { + var result = Generate.IpV4(ipV4Amount); + Console.WriteLine(result); + return; + } + + if (ipV6Amount is not 0) + { + var result = Generate.IpV6(ipV6Amount); + Console.WriteLine(result); + return; + } + else + generateCommand.Invoke("--help"); + }, + generateV4Option, + generateV6Option + ); + + return rootCommand.Invoke(args); } } \ No newline at end of file diff --git a/cli/src/Validate.cs b/cli/src/Validate.cs deleted file mode 100644 index 7251f2a..0000000 --- a/cli/src/Validate.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace ValidIp; - -class Validate -{ - public static void IpV4(string ipV4) - { - // TODO - Console.WriteLine($"Validating... {ipV4} IPv4"); - } - - public static void IpV6(string ipV6) - { - // TODO - Console.WriteLine($"Validating... {ipV6} IPv6"); - } -} \ No newline at end of file diff --git a/cli/valid-ip.csproj b/cli/valid-ip.csproj index d33a8a8..69b377a 100644 --- a/cli/valid-ip.csproj +++ b/cli/valid-ip.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/lib/dotnet/.gitignore b/lib/dotnet/.gitignore new file mode 100644 index 0000000..6a72562 --- /dev/null +++ b/lib/dotnet/.gitignore @@ -0,0 +1,454 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# JetBrains Rider +.idea/ +*.sln.iml + +## +## Visual Studio Code +## +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json \ No newline at end of file diff --git a/library/LICENSE.md b/lib/dotnet/LICENSE.md similarity index 100% rename from library/LICENSE.md rename to lib/dotnet/LICENSE.md diff --git a/lib/dotnet/README.md b/lib/dotnet/README.md new file mode 100644 index 0000000..7203e88 --- /dev/null +++ b/lib/dotnet/README.md @@ -0,0 +1,3 @@ +## Valid IP .NET Lib + +// TODO: README \ No newline at end of file diff --git a/lib/dotnet/ValidIp.csproj b/lib/dotnet/ValidIp.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/lib/dotnet/ValidIp.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/lib/dotnet/nuget.config b/lib/dotnet/nuget.config new file mode 100644 index 0000000..6ce9759 --- /dev/null +++ b/lib/dotnet/nuget.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/lib/dotnet/src/Generate.cs b/lib/dotnet/src/Generate.cs new file mode 100644 index 0000000..ebee4e1 --- /dev/null +++ b/lib/dotnet/src/Generate.cs @@ -0,0 +1,16 @@ +namespace ValidIp; + +public class Generate +{ + public static string IpV4(int generateAmount) + { + // TODO + return $"Generating... {generateAmount} x ipV4"; + } + + public static string IpV6(int generateAmount) + { + // TODO + return $"Generating... {generateAmount} x ipV6"; + } +} \ No newline at end of file diff --git a/lib/dotnet/src/Validate.cs b/lib/dotnet/src/Validate.cs new file mode 100644 index 0000000..80802fe --- /dev/null +++ b/lib/dotnet/src/Validate.cs @@ -0,0 +1,16 @@ +namespace ValidIp; + +public class Validate +{ + public static string IpV4(string ipV4) + { + // TODO + return $"Validating... {ipV4} IPv4"; + } + + public static string IpV6(string ipV6) + { + // TODO + return $"Validating... {ipV6} IPv6"; + } +} \ No newline at end of file diff --git a/library/.gitignore b/lib/nodejs/.gitignore similarity index 100% rename from library/.gitignore rename to lib/nodejs/.gitignore diff --git a/lib/nodejs/LICENSE.md b/lib/nodejs/LICENSE.md new file mode 100644 index 0000000..0cebe88 --- /dev/null +++ b/lib/nodejs/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Mateus Abelli + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/nodejs/README.md b/lib/nodejs/README.md new file mode 100644 index 0000000..5402625 --- /dev/null +++ b/lib/nodejs/README.md @@ -0,0 +1,62 @@ +# Valid IP Library + +![npm](https://img.shields.io/npm/dt/valid-ip) +![npm](https://img.shields.io/npm/v/valid-ip) +[![Node.js CI](https://github.com/mateusabelli/valid-ip/actions/workflows/node.js.yml/badge.svg?branch=main)](https://github.com/mateusabelli/valid-ip/actions/workflows/node.js.yml) +[![NPM Package](https://github.com/mateusabelli/valid-ip/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/mateusabelli/valid-ip/actions/workflows/npm-publish.yml) + +**valid-ip** is a small and reliable **IPv4** and **IPv6** validation library. + +- [Installation](#installation) +- [Documentation](#documentation) +- [References](#references) +- [License](#license) + +## Installation + +``` +npm i valid-ip +``` + +## Documentation + +### Example + +```javascript +const { isV4, isV6 } = require('valid-ip') + +isV4('175.21.195.5') // true + +isV6('5b93:c18f:27e6:f322:530a:1a5d:74c8:e2c2') // true +``` + +### How it works + +The functions receives a string parameter and process the value to validate if it matches the following rules: + +An IPv4 address has the format: x . x . x . x where x is called +an octet and must be a decimal value between 0 and 255. + +- No leading 0 +- In range of (0 - 255) +- Has exactly 4 cells +- Has an integer in each cell + +An IPv6 address has the format x : x : x : x : x : x : x : x, where +x is called a segment and can be any hexadecimal value between 0 and FFFF. + +- Can be composed to just one 0 +- In hexadecimal range of (0000 - FFFF) +- Has exactly 8 cells +- No cells are empty + +## References + +- https://www.youtube.com/watch?v=EB5FAwHqpm4 +- https://www.ibm.com/docs/en/ts3500-tape-library?topic=functionality-ipv4-ipv6-address-formats +- https://stackoverflow.com/questions/5284147/validating-ipv4-addresses-with-regexp +- https://regex101.com/ + +## License + +MIT License diff --git a/library/jsconfig.json b/lib/nodejs/jsconfig.json similarity index 100% rename from library/jsconfig.json rename to lib/nodejs/jsconfig.json diff --git a/library/package.json b/lib/nodejs/package.json similarity index 100% rename from library/package.json rename to lib/nodejs/package.json diff --git a/library/pnpm-lock.yaml b/lib/nodejs/pnpm-lock.yaml similarity index 100% rename from library/pnpm-lock.yaml rename to lib/nodejs/pnpm-lock.yaml diff --git a/library/src/index.js b/lib/nodejs/src/index.js similarity index 100% rename from library/src/index.js rename to lib/nodejs/src/index.js diff --git a/library/src/test/index.test.js b/lib/nodejs/src/test/index.test.js similarity index 100% rename from library/src/test/index.test.js rename to lib/nodejs/src/test/index.test.js diff --git a/library/src/types/index.d.ts b/lib/nodejs/src/types/index.d.ts similarity index 100% rename from library/src/types/index.d.ts rename to lib/nodejs/src/types/index.d.ts diff --git a/library/README.md b/library/README.md deleted file mode 100644 index 8cb69c5..0000000 --- a/library/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Valid IP Library - -// TODO: README \ No newline at end of file From 24eaa1b0679bbd57536ce2c666a0c204f35e80b5 Mon Sep 17 00:00:00 2001 From: Mateus Abelli Date: Sat, 22 Apr 2023 18:02:34 -0300 Subject: [PATCH 2/2] Fix Dependabot directory for npm --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a6488ed..2d25614 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,7 +7,7 @@ version: 2 updates: # Maintain dependencies for NPM - package-ecosystem: "npm" - directory: "library" + directory: "lib/nodejs" schedule: interval: "weekly"