Comparing version 0.1.0 to 0.2.0
@@ -174,3 +174,3 @@ // Generated by LiveScript 1.2.0 | ||
type: 'Just', | ||
value: that[1] | ||
value: that[1].replace("\\'", "'") | ||
}; | ||
@@ -180,3 +180,3 @@ } else if (that = it.match(/^"(.*)"$/)) { | ||
type: 'Just', | ||
value: that[1] | ||
value: that[1].replace('\\"', '"') | ||
}; | ||
@@ -212,3 +212,3 @@ } else { | ||
function castTuple(node, type, options){ | ||
var result, i$, ref$, len$, i, types, cast; | ||
var result, i, i$, ref$, len$, types, cast; | ||
if (toString$.call(node).slice(8, -1) !== 'Array') { | ||
@@ -220,4 +220,4 @@ return { | ||
result = []; | ||
i = 0; | ||
for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) { | ||
i = i$; | ||
types = ref$[i$]; | ||
@@ -228,7 +228,14 @@ cast = typesCast(node[i], types, options); | ||
} | ||
i++; | ||
} | ||
return { | ||
type: 'Just', | ||
value: result | ||
}; | ||
if (node.length <= i) { | ||
return { | ||
type: 'Just', | ||
value: result | ||
}; | ||
} else { | ||
return { | ||
type: 'Nothing' | ||
}; | ||
} | ||
} | ||
@@ -235,0 +242,0 @@ function castFields(node, type, options){ |
@@ -17,9 +17,10 @@ // Generated by LiveScript 1.2.0 | ||
} | ||
function consumeList(tokens, delimiters, hasDelimiters){ | ||
var result; | ||
function consumeList(tokens, arg$, hasDelimiters){ | ||
var open, close, result; | ||
open = arg$[0], close = arg$[1]; | ||
if (hasDelimiters) { | ||
consumeOp(tokens, delimiters[0]); | ||
consumeOp(tokens, open); | ||
} | ||
result = []; | ||
while (tokens.length && tokens[0] !== delimiters[1]) { | ||
while (tokens.length && tokens[0] !== close) { | ||
result.push(consumeElement(tokens)); | ||
@@ -29,3 +30,3 @@ maybeConsumeOp(tokens, ','); | ||
if (hasDelimiters) { | ||
consumeOp(tokens, delimiters[1]); | ||
consumeOp(tokens, close); | ||
} | ||
@@ -92,6 +93,9 @@ return result; | ||
special = /\[\]\(\)}{:,/.source; | ||
tokenRegex = RegExp('("(?:[^"]|\\\\")*")|(\'(?:[^\']|\\\\\')*\')|(#.*#)|(/(?:\\\\/|[^/])*/[gimy]*)|([' + special + '])|([^\\s' + special + ']+)|\\s*'); | ||
tokenRegex = RegExp('("(?:[^"]|\\\\")*")|(\'(?:[^\']|\\\\\')*\')|(#.*#)|(/(?:\\\\/|[^/])*/[gimy]*)|([' + special + '])|([^\\s' + special + '](?:\\s*[^\\s' + special + ']+)*)|\\s*'); | ||
module.exports = function(types, string, options){ | ||
var tokens, node; | ||
options == null && (options = {}); | ||
if (!options.explicit && types.length === 1 && types[0].type === 'String') { | ||
return string; | ||
} | ||
tokens = reject(function(it){ | ||
@@ -98,0 +102,0 @@ return !it || /^\s+$/.test(it); |
{ | ||
"name": "levn", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "George Zahariev <z@georgezahariev.com>", | ||
"description": "Light ECMAScript (JavaScript) Value Notation - human written, concise, typed, flexible", | ||
"homepage": "https//github.com/gkz/levn", | ||
"homepage": "https://github.com/gkz/levn", | ||
"keywords": [ | ||
@@ -45,3 +45,3 @@ "levn", | ||
"prelude-ls": "~1.0.3", | ||
"type-check": "~0.2.0" | ||
"type-check": "~0.3.0" | ||
}, | ||
@@ -48,0 +48,0 @@ "devDependencies": { |
@@ -1,2 +0,2 @@ | ||
# levn | ||
# levn [![Build Status](https://travis-ci.org/gkz/levn.png)](https://travis-ci.org/gkz/levn) | ||
<a name="levn" /> | ||
@@ -7,3 +7,3 @@ __Light ECMAScript (JavaScript) Value Notation__ | ||
Levn aims to concisely describe JavaScript values in text, and allow for the extraction and validation of those values. Levn uses [type-check](https://github.com/gkz/type-check) for its type format, and to validate the results. MIT license. Version 0.1.0. | ||
Levn aims to concisely describe JavaScript values in text, and allow for the extraction and validation of those values. Levn uses [type-check](https://github.com/gkz/type-check) for its type format, and to validate the results. MIT license. Version 0.2.0. | ||
@@ -24,3 +24,3 @@ __How is this different than JSON?__ levn is meant to be written by humans only, is (due to the previous point) much more concise, can be validated against supplied types, has regex and date literals, and can easily be extended with custom types. On the other hand, it is probably slower and thus less efficient at transporting large amounts of data, which is fine since this is not its purpose. | ||
parse('String', 'levn'); // 'levn' | ||
parse('String', '"a b"'); // 'a b' | ||
parse('String', 'a b'); // 'a b' | ||
parse('Boolean', 'true'); // true | ||
@@ -45,7 +45,4 @@ | ||
// commas are always optional | ||
parse('[Number]', '1 2 3'); // [1,2,3] | ||
// wildcard - auto choose type | ||
parse('*', '[hi (null [42]) {k: true}]'); // ['hi', [null, [42]], {k: true}] | ||
parse('*', '[hi,(null,[42]),{k: true}]'); // ['hi', [null, [42]], {k: true}] | ||
``` | ||
@@ -110,18 +107,19 @@ ## Usage | ||
* `undefined`, `null`, `NaN`, `true`, and `false` are all their JavaScript equivalents | ||
* `[element1, element2, etc]` is an Array, and the casting procedure is recursively applied to each element. Eg. `[1,2,3]` is `[1,2,3]`. Commas are always optional. | ||
* `(element1, element2, etc)` is an tuple, and the casting procedure is recursively applied to each element. Eg. `(1, a)` is `(1, a)` (is `[1, 'a']`. Commas are always optional. | ||
* `{key1: val1, key2: val2, ...}` is an Object, and the casting procedure is recursively applied to each property. Eg. `{a: 1, b: 2}` is `{a: 1, b: 2}`. Commas are always optional. | ||
* Any test which does not fall under the above, and which does not contain spaces or other special characters (`[``]``(``)``{``}``:``,`) is a string, eg. `$12-blah` is `"$12-blah"`. | ||
* `[element1, element2, etc]` is an Array, and the casting procedure is recursively applied to each element. Eg. `[1,2,3]` is `[1,2,3]`. | ||
* `(element1, element2, etc)` is an tuple, and the casting procedure is recursively applied to each element. Eg. `(1, a)` is `(1, a)` (is `[1, 'a']`). | ||
* `{key1: val1, key2: val2, ...}` is an Object, and the casting procedure is recursively applied to each property. Eg. `{a: 1, b: 2}` is `{a: 1, b: 2}`. | ||
* Any test which does not fall under the above, and which does not contain special characters (`[``]``(``)``{``}``:``,`) is a string, eg. `$12- blah` is `"$12- blah"`. | ||
If you do provide type information, you can make your input more concise as the program already has some information about what it expects. Please see the [type format](https://github.com/gkz/type-check#type-format) section of [type-check](https://github.com/gkz/type-check) for more information about how to specify types. There are some rules about what levn can do with the information: | ||
* If a String is expected, and only a String, all characters of the input (including any special ones) will become part of the output. Eg. `[({})]` is `"[({})]"`. | ||
* If a Date is expected, the surrounding `#` can be omitted from date literals. Eg. `2011-11-11` is `new Date('2011-11-11')` | ||
* If a RegExp is expected, no flags need to be specified, and the regex is not using any of the special characters,the opening and closing `/` can be omitted - this will have the affect of setting the source of the regex to the input. Eg. `regex` is `/regex/` | ||
* If an Array is expected, and it is the root node (at the top level), the opening `[` and closing `]` can be omitted. Eg. `1,2,3` is `[1,2,3]` - also remember that commas are optional so `1 2 3` is `[1,2,3]`. | ||
* If a tuple is expected, and it is the root node (at the top level), the opening `(` and closing `)` can be omitted. Eg. `1, a` is `(1, a)` (is `[1, 'a']`) - also remember that commas are optional so `1 a` is `(1, a)`. | ||
* If an Object is expected, and it is the root node (at the top level), the opening `{` and closing `}` can be omitted. Eg `a: 1, b: 2` is `{a: 1, b: 2}`. Commas can be omitted but would you really want to? | ||
* If an Array is expected, and it is the root node (at the top level), the opening `[` and closing `]` can be omitted. Eg. `1,2,3` is `[1,2,3]`. | ||
* If a tuple is expected, and it is the root node (at the top level), the opening `(` and closing `)` can be omitted. Eg. `1, a` is `(1, a)` (is `[1, 'a']`). | ||
* If an Object is expected, and it is the root node (at the top level), the opening `{` and closing `}` can be omitted. Eg `a: 1, b: 2` is `{a: 1, b: 2}`. | ||
If you list multiple types (eg. `Number | String`), it will first attempt to cast to the first type and then validate - if the validation fails it will move on to the next type and so forth, left to right. You must be careful as some types will succeed with any input, such as String. Thus put String at the end of your list. In non-explicit mode, Date and RegExp will succeed with a large variety of input - also be careful with these and list them near the end if not last in your list. | ||
Note that whitespace is inconsequential in all cases other than separating elements. | ||
Whitespace between special characters and elements is inconsequential. | ||
@@ -203,2 +201,2 @@ ## Options | ||
`levn` is written in [LiveScript](http://livescript.net/) - a langauge that compiles to JavaScript. It uses [type-check](https://github.com/gkz/type-check) to both parse types and validate values. It also uses the [prelude.ls](http://preludels.com/) library. | ||
`levn` is written in [LiveScript](http://livescript.net/) - a language that compiles to JavaScript. It uses [type-check](https://github.com/gkz/type-check) to both parse types and validate values. It also uses the [prelude.ls](http://preludels.com/) library. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33720
812
198
+ Addedprelude-ls@1.1.2(transitive)
+ Addedtype-check@0.3.2(transitive)
- Removedtype-check@0.2.0(transitive)
Updatedtype-check@~0.3.0