dart-lang/path

[Question] Is it possible to enforce style or context?

Closed this issue · 1 comments

Hi!

I would like to know if it is possible to enforce style or context for path manipulation in particular scopes.

For my use case, I would like to use posix separator (/) even on Windows.

I tried the following:

final myPath = p.Style.posix.context.normalize(
  p.join(
    'this',
    'is',
    'my',
    'path',
  ),
);

print(myPath);

I also tried the following:

final myPath = p.posix.normalize(
  p.join(
    'this',
    'is',
    'my',
    'path',
  ),
);

print(myPath);

But the following is printed on Windows:

this\is\my\path

My expected output is:

this/is/my/path

Thanks in advance! 😄

You want:

final myPath = p.posix.normalize(
  p.posix.join( // <--
    'this',
    'is',
    'my',
    'path',
  ),
);

The top level functions always use the host path style, so if you want a specific style, you need to mention it on every function call.