Skip to content

Commit

Permalink
chore: Rename jsany to jany
Browse files Browse the repository at this point in the history
Unfortunately, mistakes on vpm cannot be fixed.

BREAKING CHANGE: The type Any is imported from `prantlf.jany`
instead of from `pratlf.jsany`. You have to rename the import
module name in your sources.
  • Loading branch information
prantlf committed Jun 6, 2023
1 parent eac8fde commit 3e9a2eb
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jsany
jany
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Strictly parse and format YAML data.
* Works with the `Any` type suitable for safe handling of JSON/YAML data.
* Allows unmarshalling the YAML contents to a static V type.

Uses [jsany]. See also the [json] package.
Uses [jany]. See also the [json] package.

## Synopsis

Expand Down Expand Up @@ -55,17 +55,18 @@ ln -s ../v-yaml yaml

V will resolve the import `yaml` to the symlinked directory.

You will usually need the `Any` type as well:
You will usually need the `Any` type as well, either from [VPM] or from GitHub:

```txt
v install --git https://github.com/prantlf/v-jsany
v install prantlf.jany
v install --git https://github.com/prantlf/v-jany
```

## API

### parse_text(input string) !Any

Parses an input string in the YAML format to an `Any` value. See [jsany] for more information about the `Any` type.
Parses an input string in the YAML format to an `Any` value. See [jany] for more information about the `Any` type.

```go
input := r'
Expand All @@ -76,15 +77,15 @@ any := parse_text(input)

### parse_file(path string) !Any

Loads the contents of a text file in the YAML format and parses it to an `Any` value. See [jsany] for more information about the `Any` type.
Loads the contents of a text file in the YAML format and parses it to an `Any` value. See [jany] for more information about the `Any` type.

```go
any := parse_file('config.yaml')
```

### unmarshal_text[T](input string, opts UnmarshalOpts) !T

Unmarshals an input string in the YAML format to an instance of `T`. See [jsany] for more information about the `Any` type and the `UnmarshalOpts` struct.
Unmarshals an input string in the YAML format to an instance of `T`. See [jany] for more information about the `Any` type and the `UnmarshalOpts` struct.

```go
struct Config {
Expand All @@ -99,7 +100,7 @@ config := unmarshal_text[Config](input)

### unmarshal_file[T](path string, opts UnmarshalOpts) !T

Loads the contents of a text file in the YAML format and unmarshals it to an instance of `T`. See [jsany] for more information about the `Any` type and the `UnmarshalOpts` struct.
Loads the contents of a text file in the YAML format and unmarshals it to an instance of `T`. See [jany] for more information about the `Any` type and the `UnmarshalOpts` struct.

```go
struct Config {
Expand All @@ -118,7 +119,7 @@ This is a work in progress.
* Add `marshal_*` functions.
* Enable support for arrays (bug [#18317]).

[VPM]: https://vpm.vlang.io/packages/prantlf.jsany
[jsany]: https://github.com/prantlf/v-jsany
[VPM]: https://vpm.vlang.io/packages/prantlf.jany
[jany]: https://github.com/prantlf/v-jany
[json]: https://github.com/prantlf/v-json
[#18317]: https://github.com/vlang/v/issues/18317
2 changes: 1 addition & 1 deletion errors.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module yaml

import jsany { Any }
import jany { Any }

pub struct YamlError {
Error
Expand Down
6 changes: 3 additions & 3 deletions parse.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module yaml

import os
import jsany { Any }
import jany { Any }

fn C.strtod(charptr, &charptr) f64

Expand Down Expand Up @@ -57,7 +57,7 @@ fn parse(parser &C.yaml_parser_t) !Any {
continue
}
C.YAML_STREAM_END_EVENT {
return Any(jsany.null)
return Any(jany.null)
}
C.YAML_MAPPING_START_EVENT {
return parse_object(parser)
Expand Down Expand Up @@ -175,7 +175,7 @@ fn parse_value(parser &C.yaml_parser_t, event &C.yaml_event_t) !Any {
C.YAML_PLAIN_SCALAR_STYLE {
match raw {
'null' {
return Any(jsany.null)
return Any(jany.null)
}
'true' {
return Any(true)
Expand Down
2 changes: 1 addition & 1 deletion unmarshal.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module yaml

import jsany { UnmarshalOpts, unmarshal }
import jany { UnmarshalOpts, unmarshal }

pub fn unmarshal_file[T](path string, opts UnmarshalOpts) !T {
a := parse_file(path)!
Expand Down
2 changes: 1 addition & 1 deletion unmarshal_test.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module yaml

import jsany { UnmarshalOpts }
import jany { UnmarshalOpts }

fn test_unmarshal_null_to_scalar() {
unmarshal_text[int]('', UnmarshalOpts{}) or {
Expand Down
2 changes: 1 addition & 1 deletion v.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Module {
name: 'yaml',
description: 'Strictly parse and format YAML data.',
version: '0.0.1'
dependencies: ['jsany']
dependencies: ['jany']
}

0 comments on commit 3e9a2eb

Please sign in to comment.