简体   繁体   English

路径元素的命名约定

[英]Naming convention for path elements

I'm actually looking for a good path convention and mostly where to store / between elements: 实际上,我在寻找一个好的路径公约,并大多在哪里存储/元素之间:

  • At the end of the directory const dir = "example/" 在目录末尾const dir = "example/"
  • At the start of the following element const file = "/example1.md" 在以下元素的开头const file = "/example1.md"
  • None of them (allow to use Array.join('/') ) 它们都不是(允许使用Array.join('/')

I was looking into the URL convention to try to find a good practice but it didn't talk about the path. 我一直在寻找URL约定以尝试找到一种好的做法,但是它没有谈论路径。

Example

Let's see into a real example 让我们看一个真实的例子

const base_url = process.env.API_URL // http://localhost:3000(/)
const endpoint_path = "(/)users/auth(/)" 
const endpoint_name = "(/)tfa-validation"

// Slash before of after
let path = base_url + endpoint_path + endpoint_name; 
// Or without slash
path = `${base_url}/${endpoint_path}/${endpoint_name}`; 
path = [base_url, endpoint_path, endpoint_name].join('/')

Do a convention already exist ? 约定已经​​存在吗? Do a solution have any advantage ? 解决方案有什么优势吗?

I don't think there is any convention for this. 我认为这没有任何约定。 So, my opinion is: 所以,我的看法是:

  1. Do not use '/' either in the endpoint path or name. 请勿在端点路径或名称中使用“ /”。 Keep them clean because you may want to use those variables isolated; 保持它们整洁,因为您可能想孤立地使用这些变量。
  2. Use the join function because is cleaner. 使用联接功能是因为它更干净。

const base_url = process.env.API_URL // http://localhost:3000
const endpoint_path = "users/auth" 
const endpoint_name = "tfa-validation"

path = [base_url, endpoint_path, endpoint_name].join('/')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM