@gram-data/gram-value
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -176,9 +176,3 @@ 'use strict'; | ||
if (gramAst.isGramLiteralArray(recordValue)) { | ||
return recordValue.map(function (v) { | ||
return valueOf(v); | ||
}); | ||
} else if (gramAst.isLiteral(recordValue)) { | ||
return literalValueEvaluator(recordValue); | ||
} else if (gramAst.isGramRecord(recordValue)) { | ||
if (gramAst.isGramRecord(recordValue)) { | ||
return recordValue.reduce(function (acc, property) { | ||
@@ -188,2 +182,17 @@ acc[property.name] = valueOf(property.value); | ||
}, {}); | ||
} else { | ||
if (gramAst.isGramLiteralArray(recordValue)) { | ||
return recordValue.map(function (v) { | ||
return valueOf(v); | ||
}); | ||
} else if (gramAst.isLiteral(recordValue)) { | ||
return literalValueEvaluator(recordValue); | ||
} else if (typeof recordValue === 'object') { | ||
return Object.entries(recordValue).reduce(function (acc, _ref) { | ||
var k = _ref[0], | ||
v = _ref[1]; | ||
acc[k] = valueOf(v); | ||
return acc; | ||
}, {}); | ||
} | ||
} | ||
@@ -240,3 +249,3 @@ }; | ||
default: | ||
assertNever(ast); | ||
return 'TODO'; | ||
} | ||
@@ -243,0 +252,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-ast");function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function t(e){return(t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,r){return(n=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,r,t){return(u=a()?Reflect.construct:function(e,r,t){var a=[null];a.push.apply(a,r);var u=new(Function.bind.apply(e,a));return t&&n(u,t.prototype),u}).apply(null,arguments)}function o(e){var r="function"==typeof Map?new Map:void 0;return(o=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,a)}function a(){return u(e,arguments,t(this).constructor)}return a.prototype=Object.create(e.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),n(a,e)})(e)}var i=require("unist-util-visit"),s={literalValueEvaluator:w},c=/^([+-]\d{4,}\b|\d{4})$/,l=/^([0-9]{4})-(1[0-2]|0[1-9])$/,f=/^([0-9]{4})(-?)(1[0-2]|0[1-9])\2(3[01]|0[1-9]|[12][0-9])$/,p=/^(2[0-3]|[01][0-9]):?([0-5][0-9]):?([0-5][0-9](\.[0-9]{3})?)?(Z|([+-])((?:2[0-3]|[01][0-9]))(?::?([0-5][0-9]))?)?$/,v=/^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+)S)?)?$/,m=function(e){var r,t;function n(r){var t;return(t=e.call(this,"AST is invalid:"+JSON.stringify(r))||this).name="InvalidAstError",t.ast=r,t}return t=e,(r=n).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,n}(o(Error)),b=function r(t,n){return void 0===n&&(n=w),e.isGramLiteralArray(t)?t.map((function(e){return r(e)})):e.isLiteral(t)?n(t):e.isGramRecord(t)?t.reduce((function(e,t){return e[t.name]=r(t.value),e}),{}):void 0};function d(e){throw new Error("Unexpected object: "+e)}var w=function(e){switch(e.type){case"boolean":return x(e);case"string":return O(e);case"integer":return g(e);case"decimal":return N(e);case"hexadecimal":return I(e);case"octal":return D(e);case"tagged":switch(e.tag){case"date":return y(e);case"time":return h(e);case"datetime":case"interval":case"duration":return"TODO";case"uri":return e.value;case"wkt":return"TODO";default:d(e)}case"measurement":return"measure by measure";default:return d(e)}},x=function(e){return e.value&&"true"===e.value.toLowerCase()},O=function(e){if(e.value)return e.value;throw new m(e)},y=function(e){if(e.value){var r=f.exec(e.value);if(r)return new Date(Date.UTC(Number.parseInt(r[1]),Number.parseInt(r[3])-1,Number.parseInt(r[4])));if(r=l.exec(e.value))return new Date(Date.UTC(Number.parseInt(r[1]),Number.parseInt(r[2])));if(r=c.exec(e.value))return new Date(Number.parseInt(r[1]),1);throw SyntaxError("Unable to parse date from "+e.value)}throw new m(e)},h=function(e){if(e.value){var r=p.exec(e.value);if(r){var t=Number.parseInt(r[1]),n=r[1]?Number.parseInt(r[2]):0,a=r[3]?Number.parseFloat(r[3]):0,u=r[5],o=36e5*t+6e4*n+1e3*a;if(u){var i="Z"===u?0:36e5*Number.parseInt(r[7])+6e4*Number.parseInt(r[8]||"0");return new Date("-"===r[6]?o+i:o-i)}return new Date(o)}throw SyntaxError("Unable to parse time from "+e.value)}throw new m(e)},g=function(e){if(e.value)return Number.parseInt(e.value);throw new m(e)},N=function(e){if(e.value)return Number.parseFloat(e.value);throw new m(e)},I=function(e){if(e.value)return Number.parseInt(e.value,16);throw new m(e)},D=function(e){if(e.value)return Number.parseInt(e.value,8);throw new m(e)};exports.gramValuePlugin=function(t){var n=r({},s,t);return function(r){i(r,(function(r){e.isGramPath(r)&&r.record&&(r.data=Object.assign(r.data||{},{value:b(r.record,n.literalValueEvaluator)}))}))}},exports.iso8601Duration=v,exports.iso8601LocalTime=/^(2[0-3]|[01][0-9]):?([0-5][0-9])(:?([0-5][0-9](\.[0-9]{3})?))?$/,exports.iso8601OrdinalDate=/^([0-9]{4})-?(36[0-6]|3[0-5][0-9]|[12][0-9]{2}|0[1-9][0-9]|00[1-9])$/,exports.iso8601Repeat=/^R(\d*)$/,exports.iso8601Time=p,exports.iso8601WeekDate=/^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])-?([1-7])$/,exports.iso8601WeekOfYear=/^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])$/,exports.iso8601Year=c,exports.iso8601YearMonth=l,exports.iso8601YearMonthDay=f,exports.valueOf=b,exports.valueOfBoolean=x,exports.valueOfDate=y,exports.valueOfDecimal=N,exports.valueOfDuration=function(e){if(e.value){var r=v.exec(e.value);if(r){var t=r[2]?Number.parseInt(r[2]):0,n=r[4]?Number.parseInt(r[4]):0,a=r[6]?Number.parseInt(r[6]):0,u=r[9]?Number.parseInt(r[9]):0,o=r[11]?Number.parseInt(r[11]):0,i=r[13]?Number.parseInt(r[13]):0;return new Date(31536e6*t+2592e6*n+864e5*a+36e5*u+6e4*o+1e3*i)}throw SyntaxError("Unable to parse duration from "+e.value)}throw new m(e)},exports.valueOfHexadecimal=I,exports.valueOfInteger=g,exports.valueOfLiteral=w,exports.valueOfMeasurement=function(e){if(e.value)return Number.parseInt(e.value);throw new m(e)},exports.valueOfOctal=D,exports.valueOfString=O,exports.valueOfTaggedLiteral=function(e){if(e.value)return e.value;throw new m(e)},exports.valueOfTime=h; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-ast");function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function t(e){return(t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,r){return(n=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,r,t){return(u=a()?Reflect.construct:function(e,r,t){var a=[null];a.push.apply(a,r);var u=new(Function.bind.apply(e,a));return t&&n(u,t.prototype),u}).apply(null,arguments)}function o(e){var r="function"==typeof Map?new Map:void 0;return(o=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,a)}function a(){return u(e,arguments,t(this).constructor)}return a.prototype=Object.create(e.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),n(a,e)})(e)}var i=require("unist-util-visit"),s={literalValueEvaluator:d},c=/^([+-]\d{4,}\b|\d{4})$/,l=/^([0-9]{4})-(1[0-2]|0[1-9])$/,f=/^([0-9]{4})(-?)(1[0-2]|0[1-9])\2(3[01]|0[1-9]|[12][0-9])$/,p=/^(2[0-3]|[01][0-9]):?([0-5][0-9]):?([0-5][0-9](\.[0-9]{3})?)?(Z|([+-])((?:2[0-3]|[01][0-9]))(?::?([0-5][0-9]))?)?$/,v=/^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+)S)?)?$/,m=function(e){var r,t;function n(r){var t;return(t=e.call(this,"AST is invalid:"+JSON.stringify(r))||this).name="InvalidAstError",t.ast=r,t}return t=e,(r=n).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,n}(o(Error)),b=function r(t,n){return void 0===n&&(n=d),e.isGramRecord(t)?t.reduce((function(e,t){return e[t.name]=r(t.value),e}),{}):e.isGramLiteralArray(t)?t.map((function(e){return r(e)})):e.isLiteral(t)?n(t):"object"==typeof t?Object.entries(t).reduce((function(e,t){return e[t[0]]=r(t[1]),e}),{}):void 0},d=function(e){switch(e.type){case"boolean":return w(e);case"string":return x(e);case"integer":return h(e);case"decimal":return g(e);case"hexadecimal":return N(e);case"octal":return I(e);case"tagged":switch(e.tag){case"date":return O(e);case"time":return y(e);case"datetime":case"interval":case"duration":return"TODO";case"uri":return e.value;case"wkt":default:return"TODO"}case"measurement":return"measure by measure";default:return function(e){throw new Error("Unexpected object: "+e)}(e)}},w=function(e){return e.value&&"true"===e.value.toLowerCase()},x=function(e){if(e.value)return e.value;throw new m(e)},O=function(e){if(e.value){var r=f.exec(e.value);if(r)return new Date(Date.UTC(Number.parseInt(r[1]),Number.parseInt(r[3])-1,Number.parseInt(r[4])));if(r=l.exec(e.value))return new Date(Date.UTC(Number.parseInt(r[1]),Number.parseInt(r[2])));if(r=c.exec(e.value))return new Date(Number.parseInt(r[1]),1);throw SyntaxError("Unable to parse date from "+e.value)}throw new m(e)},y=function(e){if(e.value){var r=p.exec(e.value);if(r){var t=Number.parseInt(r[1]),n=r[1]?Number.parseInt(r[2]):0,a=r[3]?Number.parseFloat(r[3]):0,u=r[5],o=36e5*t+6e4*n+1e3*a;if(u){var i="Z"===u?0:36e5*Number.parseInt(r[7])+6e4*Number.parseInt(r[8]||"0");return new Date("-"===r[6]?o+i:o-i)}return new Date(o)}throw SyntaxError("Unable to parse time from "+e.value)}throw new m(e)},h=function(e){if(e.value)return Number.parseInt(e.value);throw new m(e)},g=function(e){if(e.value)return Number.parseFloat(e.value);throw new m(e)},N=function(e){if(e.value)return Number.parseInt(e.value,16);throw new m(e)},I=function(e){if(e.value)return Number.parseInt(e.value,8);throw new m(e)};exports.gramValuePlugin=function(t){var n=r({},s,t);return function(r){i(r,(function(r){e.isGramPath(r)&&r.record&&(r.data=Object.assign(r.data||{},{value:b(r.record,n.literalValueEvaluator)}))}))}},exports.iso8601Duration=v,exports.iso8601LocalTime=/^(2[0-3]|[01][0-9]):?([0-5][0-9])(:?([0-5][0-9](\.[0-9]{3})?))?$/,exports.iso8601OrdinalDate=/^([0-9]{4})-?(36[0-6]|3[0-5][0-9]|[12][0-9]{2}|0[1-9][0-9]|00[1-9])$/,exports.iso8601Repeat=/^R(\d*)$/,exports.iso8601Time=p,exports.iso8601WeekDate=/^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])-?([1-7])$/,exports.iso8601WeekOfYear=/^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])$/,exports.iso8601Year=c,exports.iso8601YearMonth=l,exports.iso8601YearMonthDay=f,exports.valueOf=b,exports.valueOfBoolean=w,exports.valueOfDate=O,exports.valueOfDecimal=g,exports.valueOfDuration=function(e){if(e.value){var r=v.exec(e.value);if(r){var t=r[2]?Number.parseInt(r[2]):0,n=r[4]?Number.parseInt(r[4]):0,a=r[6]?Number.parseInt(r[6]):0,u=r[9]?Number.parseInt(r[9]):0,o=r[11]?Number.parseInt(r[11]):0,i=r[13]?Number.parseInt(r[13]):0;return new Date(31536e6*t+2592e6*n+864e5*a+36e5*u+6e4*o+1e3*i)}throw SyntaxError("Unable to parse duration from "+e.value)}throw new m(e)},exports.valueOfHexadecimal=N,exports.valueOfInteger=h,exports.valueOfLiteral=d,exports.valueOfMeasurement=function(e){if(e.value)return Number.parseInt(e.value);throw new m(e)},exports.valueOfOctal=I,exports.valueOfString=x,exports.valueOfTaggedLiteral=function(e){if(e.value)return e.value;throw new m(e)},exports.valueOfTime=y; | ||
//# sourceMappingURL=gram-value.cjs.production.min.js.map |
@@ -1,2 +0,2 @@ | ||
import { BooleanLiteral, StringLiteral, TaggedLiteral, DateLiteral, IntegerLiteral, MeasurementLiteral, DecimalLiteral, HexadecimalLiteral, OctalLiteral, TimeLiteral, DurationLiteral, GramRecordValue, GramLiteral } from '@gram-data/gram-ast'; | ||
import { BooleanLiteral, StringLiteral, DateLiteral, IntegerLiteral, MeasurementLiteral, DecimalLiteral, HexadecimalLiteral, OctalLiteral, TimeLiteral, DurationLiteral, GramRecordValue, GramLiteral, GramRecord, TaggedTextLiteral } from '@gram-data/gram-ast'; | ||
export declare const iso8601Year: RegExp; | ||
@@ -23,7 +23,7 @@ export declare const iso8601YearMonth: RegExp; | ||
*/ | ||
export declare const valueOf: (recordValue: GramRecordValue, literalValueEvaluator?: (ast: GramLiteral) => any) => any; | ||
export declare const valueOf: (recordValue: GramRecordValue | GramRecord, literalValueEvaluator?: (ast: GramLiteral) => any) => any; | ||
export declare const valueOfLiteral: (ast: GramLiteral) => any; | ||
export declare const valueOfBoolean: (ast: BooleanLiteral) => boolean; | ||
export declare const valueOfString: (ast: StringLiteral) => string; | ||
export declare const valueOfTaggedLiteral: (ast: TaggedLiteral) => string; | ||
export declare const valueOfTaggedLiteral: (ast: TaggedTextLiteral) => string; | ||
export declare const valueOfDate: (ast: DateLiteral) => Date; | ||
@@ -30,0 +30,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { isGramPath, isGramLiteralArray, isLiteral, isGramRecord } from '@gram-data/gram-ast'; | ||
import { isGramPath, isGramRecord, isGramLiteralArray, isLiteral } from '@gram-data/gram-ast'; | ||
@@ -172,9 +172,3 @@ function _extends() { | ||
if (isGramLiteralArray(recordValue)) { | ||
return recordValue.map(function (v) { | ||
return valueOf(v); | ||
}); | ||
} else if (isLiteral(recordValue)) { | ||
return literalValueEvaluator(recordValue); | ||
} else if (isGramRecord(recordValue)) { | ||
if (isGramRecord(recordValue)) { | ||
return recordValue.reduce(function (acc, property) { | ||
@@ -184,2 +178,17 @@ acc[property.name] = valueOf(property.value); | ||
}, {}); | ||
} else { | ||
if (isGramLiteralArray(recordValue)) { | ||
return recordValue.map(function (v) { | ||
return valueOf(v); | ||
}); | ||
} else if (isLiteral(recordValue)) { | ||
return literalValueEvaluator(recordValue); | ||
} else if (typeof recordValue === 'object') { | ||
return Object.entries(recordValue).reduce(function (acc, _ref) { | ||
var k = _ref[0], | ||
v = _ref[1]; | ||
acc[k] = valueOf(v); | ||
return acc; | ||
}, {}); | ||
} | ||
} | ||
@@ -236,3 +245,3 @@ }; | ||
default: | ||
assertNever(ast); | ||
return 'TODO'; | ||
} | ||
@@ -239,0 +248,0 @@ |
@@ -222,9 +222,3 @@ (function (global, factory) { | ||
if (isGramLiteralArray(recordValue)) { | ||
return recordValue.map(function (v) { | ||
return valueOf(v); | ||
}); | ||
} else if (isLiteral(recordValue)) { | ||
return literalValueEvaluator(recordValue); | ||
} else if (isGramRecord(recordValue)) { | ||
if (isGramRecord(recordValue)) { | ||
return recordValue.reduce(function (acc, property) { | ||
@@ -234,2 +228,17 @@ acc[property.name] = valueOf(property.value); | ||
}, {}); | ||
} else { | ||
if (isGramLiteralArray(recordValue)) { | ||
return recordValue.map(function (v) { | ||
return valueOf(v); | ||
}); | ||
} else if (isLiteral(recordValue)) { | ||
return literalValueEvaluator(recordValue); | ||
} else if (typeof recordValue === 'object') { | ||
return Object.entries(recordValue).reduce(function (acc, _ref) { | ||
var k = _ref[0], | ||
v = _ref[1]; | ||
acc[k] = valueOf(v); | ||
return acc; | ||
}, {}); | ||
} | ||
} | ||
@@ -286,3 +295,3 @@ }; | ||
default: | ||
assertNever(ast); | ||
return 'TODO'; | ||
} | ||
@@ -289,0 +298,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(((e=e||self).gram=e.gram||{},e.gram.value={}))}(this,(function(e){"use strict";function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function t(e){return(t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,r){return(n=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,r,t){return(u=a()?Reflect.construct:function(e,r,t){var a=[null];a.push.apply(a,r);var u=new(Function.bind.apply(e,a));return t&&n(u,t.prototype),u}).apply(null,arguments)}function o(e){var r="function"==typeof Map?new Map:void 0;return(o=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,a)}function a(){return u(e,arguments,t(this).constructor)}return a.prototype=Object.create(e.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),n(a,e)})(e)}var i=function(e){return!!e.type&&!!e.value&&"property"!==e.type},c=require("unist-util-visit"),f={literalValueEvaluator:w},l=/^([+-]\d{4,}\b|\d{4})$/,s=/^([0-9]{4})-(1[0-2]|0[1-9])$/,p=/^([0-9]{4})(-?)(1[0-2]|0[1-9])\2(3[01]|0[1-9]|[12][0-9])$/,v=/^(2[0-3]|[01][0-9]):?([0-5][0-9]):?([0-5][0-9](\.[0-9]{3})?)?(Z|([+-])((?:2[0-3]|[01][0-9]))(?::?([0-5][0-9]))?)?$/,m=/^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+)S)?)?$/,d=function(e){var r,t;function n(r){var t;return(t=e.call(this,"AST is invalid:"+JSON.stringify(r))||this).name="InvalidAstError",t.ast=r,t}return t=e,(r=n).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,n}(o(Error)),y=function e(r,t){return void 0===t&&(t=w),n=r,Array.isArray(n)&&i(n[0])?r.map((function(r){return e(r)})):i(r)?t(r):function(e){return Array.isArray(e)&&!!(r=e[0]).type&&"property"===r.type;var r}(r)?r.reduce((function(r,t){return r[t.name]=e(t.value),r}),{}):void 0;var n};function b(e){throw new Error("Unexpected object: "+e)}var w=function(e){switch(e.type){case"boolean":return O(e);case"string":return h(e);case"integer":return I(e);case"decimal":return D(e);case"hexadecimal":return x(e);case"octal":return _(e);case"tagged":switch(e.tag){case"date":return g(e);case"time":return N(e);case"datetime":case"interval":case"duration":return"TODO";case"uri":return e.value;case"wkt":return"TODO";default:b(e)}case"measurement":return"measure by measure";default:return b(e)}},O=function(e){return e.value&&"true"===e.value.toLowerCase()},h=function(e){if(e.value)return e.value;throw new d(e)},g=function(e){if(e.value){var r=p.exec(e.value);if(r)return new Date(Date.UTC(Number.parseInt(r[1]),Number.parseInt(r[3])-1,Number.parseInt(r[4])));if(r=s.exec(e.value))return new Date(Date.UTC(Number.parseInt(r[1]),Number.parseInt(r[2])));if(r=l.exec(e.value))return new Date(Number.parseInt(r[1]),1);throw SyntaxError("Unable to parse date from "+e.value)}throw new d(e)},N=function(e){if(e.value){var r=v.exec(e.value);if(r){var t=Number.parseInt(r[1]),n=r[1]?Number.parseInt(r[2]):0,a=r[3]?Number.parseFloat(r[3]):0,u=r[5],o=36e5*t+6e4*n+1e3*a;if(u){var i="Z"===u?0:36e5*Number.parseInt(r[7])+6e4*Number.parseInt(r[8]||"0");return new Date("-"===r[6]?o+i:o-i)}return new Date(o)}throw SyntaxError("Unable to parse time from "+e.value)}throw new d(e)},I=function(e){if(e.value)return Number.parseInt(e.value);throw new d(e)},D=function(e){if(e.value)return Number.parseFloat(e.value);throw new d(e)},x=function(e){if(e.value)return Number.parseInt(e.value,16);throw new d(e)},_=function(e){if(e.value)return Number.parseInt(e.value,8);throw new d(e)};e.gramValuePlugin=function(e){var t=r({},f,e);return function(e){c(e,(function(e){var r;(r=e).type&&"path"===r.type&&e.record&&(e.data=Object.assign(e.data||{},{value:y(e.record,t.literalValueEvaluator)}))}))}},e.iso8601Duration=m,e.iso8601LocalTime=/^(2[0-3]|[01][0-9]):?([0-5][0-9])(:?([0-5][0-9](\.[0-9]{3})?))?$/,e.iso8601OrdinalDate=/^([0-9]{4})-?(36[0-6]|3[0-5][0-9]|[12][0-9]{2}|0[1-9][0-9]|00[1-9])$/,e.iso8601Repeat=/^R(\d*)$/,e.iso8601Time=v,e.iso8601WeekDate=/^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])-?([1-7])$/,e.iso8601WeekOfYear=/^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])$/,e.iso8601Year=l,e.iso8601YearMonth=s,e.iso8601YearMonthDay=p,e.valueOf=y,e.valueOfBoolean=O,e.valueOfDate=g,e.valueOfDecimal=D,e.valueOfDuration=function(e){if(e.value){var r=m.exec(e.value);if(r){var t=r[2]?Number.parseInt(r[2]):0,n=r[4]?Number.parseInt(r[4]):0,a=r[6]?Number.parseInt(r[6]):0,u=r[9]?Number.parseInt(r[9]):0,o=r[11]?Number.parseInt(r[11]):0,i=r[13]?Number.parseInt(r[13]):0;return new Date(31536e6*t+2592e6*n+864e5*a+36e5*u+6e4*o+1e3*i)}throw SyntaxError("Unable to parse duration from "+e.value)}throw new d(e)},e.valueOfHexadecimal=x,e.valueOfInteger=I,e.valueOfLiteral=w,e.valueOfMeasurement=function(e){if(e.value)return Number.parseInt(e.value);throw new d(e)},e.valueOfOctal=_,e.valueOfString=h,e.valueOfTaggedLiteral=function(e){if(e.value)return e.value;throw new d(e)},e.valueOfTime=N,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(((e=e||self).gram=e.gram||{},e.gram.value={}))}(this,(function(e){"use strict";function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function t(e){return(t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,r){return(n=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,r,t){return(u=a()?Reflect.construct:function(e,r,t){var a=[null];a.push.apply(a,r);var u=new(Function.bind.apply(e,a));return t&&n(u,t.prototype),u}).apply(null,arguments)}function o(e){var r="function"==typeof Map?new Map:void 0;return(o=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,a)}function a(){return u(e,arguments,t(this).constructor)}return a.prototype=Object.create(e.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),n(a,e)})(e)}var i=function(e){return!!e.type&&!!e.value&&"property"!==e.type},c=require("unist-util-visit"),f={literalValueEvaluator:b},l=/^([+-]\d{4,}\b|\d{4})$/,s=/^([0-9]{4})-(1[0-2]|0[1-9])$/,p=/^([0-9]{4})(-?)(1[0-2]|0[1-9])\2(3[01]|0[1-9]|[12][0-9])$/,v=/^(2[0-3]|[01][0-9]):?([0-5][0-9]):?([0-5][0-9](\.[0-9]{3})?)?(Z|([+-])((?:2[0-3]|[01][0-9]))(?::?([0-5][0-9]))?)?$/,m=/^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+)S)?)?$/,d=function(e){var r,t;function n(r){var t;return(t=e.call(this,"AST is invalid:"+JSON.stringify(r))||this).name="InvalidAstError",t.ast=r,t}return t=e,(r=n).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,n}(o(Error)),y=function e(r,t){return void 0===t&&(t=b),a=r,Array.isArray(a)&&(n=a[0]).type&&"property"===n.type?r.reduce((function(r,t){return r[t.name]=e(t.value),r}),{}):function(e){return Array.isArray(e)&&i(e[0])}(r)?r.map((function(r){return e(r)})):i(r)?t(r):"object"==typeof r?Object.entries(r).reduce((function(r,t){return r[t[0]]=e(t[1]),r}),{}):void 0;var n,a},b=function(e){switch(e.type){case"boolean":return w(e);case"string":return O(e);case"integer":return N(e);case"decimal":return I(e);case"hexadecimal":return D(e);case"octal":return x(e);case"tagged":switch(e.tag){case"date":return h(e);case"time":return g(e);case"datetime":case"interval":case"duration":return"TODO";case"uri":return e.value;case"wkt":default:return"TODO"}case"measurement":return"measure by measure";default:return function(e){throw new Error("Unexpected object: "+e)}(e)}},w=function(e){return e.value&&"true"===e.value.toLowerCase()},O=function(e){if(e.value)return e.value;throw new d(e)},h=function(e){if(e.value){var r=p.exec(e.value);if(r)return new Date(Date.UTC(Number.parseInt(r[1]),Number.parseInt(r[3])-1,Number.parseInt(r[4])));if(r=s.exec(e.value))return new Date(Date.UTC(Number.parseInt(r[1]),Number.parseInt(r[2])));if(r=l.exec(e.value))return new Date(Number.parseInt(r[1]),1);throw SyntaxError("Unable to parse date from "+e.value)}throw new d(e)},g=function(e){if(e.value){var r=v.exec(e.value);if(r){var t=Number.parseInt(r[1]),n=r[1]?Number.parseInt(r[2]):0,a=r[3]?Number.parseFloat(r[3]):0,u=r[5],o=36e5*t+6e4*n+1e3*a;if(u){var i="Z"===u?0:36e5*Number.parseInt(r[7])+6e4*Number.parseInt(r[8]||"0");return new Date("-"===r[6]?o+i:o-i)}return new Date(o)}throw SyntaxError("Unable to parse time from "+e.value)}throw new d(e)},N=function(e){if(e.value)return Number.parseInt(e.value);throw new d(e)},I=function(e){if(e.value)return Number.parseFloat(e.value);throw new d(e)},D=function(e){if(e.value)return Number.parseInt(e.value,16);throw new d(e)},x=function(e){if(e.value)return Number.parseInt(e.value,8);throw new d(e)};e.gramValuePlugin=function(e){var t=r({},f,e);return function(e){c(e,(function(e){var r;(r=e).type&&"path"===r.type&&e.record&&(e.data=Object.assign(e.data||{},{value:y(e.record,t.literalValueEvaluator)}))}))}},e.iso8601Duration=m,e.iso8601LocalTime=/^(2[0-3]|[01][0-9]):?([0-5][0-9])(:?([0-5][0-9](\.[0-9]{3})?))?$/,e.iso8601OrdinalDate=/^([0-9]{4})-?(36[0-6]|3[0-5][0-9]|[12][0-9]{2}|0[1-9][0-9]|00[1-9])$/,e.iso8601Repeat=/^R(\d*)$/,e.iso8601Time=v,e.iso8601WeekDate=/^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])-?([1-7])$/,e.iso8601WeekOfYear=/^([0-9]{4})-?W(5[0-3]|[1-4][0-9]|0[1-9])$/,e.iso8601Year=l,e.iso8601YearMonth=s,e.iso8601YearMonthDay=p,e.valueOf=y,e.valueOfBoolean=w,e.valueOfDate=h,e.valueOfDecimal=I,e.valueOfDuration=function(e){if(e.value){var r=m.exec(e.value);if(r){var t=r[2]?Number.parseInt(r[2]):0,n=r[4]?Number.parseInt(r[4]):0,a=r[6]?Number.parseInt(r[6]):0,u=r[9]?Number.parseInt(r[9]):0,o=r[11]?Number.parseInt(r[11]):0,i=r[13]?Number.parseInt(r[13]):0;return new Date(31536e6*t+2592e6*n+864e5*a+36e5*u+6e4*o+1e3*i)}throw SyntaxError("Unable to parse duration from "+e.value)}throw new d(e)},e.valueOfHexadecimal=D,e.valueOfInteger=N,e.valueOfLiteral=b,e.valueOfMeasurement=function(e){if(e.value)return Number.parseInt(e.value);throw new d(e)},e.valueOfOctal=x,e.valueOfString=O,e.valueOfTaggedLiteral=function(e){if(e.value)return e.value;throw new d(e)},e.valueOfTime=g,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=gram-value.umd.production.min.js.map |
{ | ||
"name": "@gram-data/gram-value", | ||
"description": "Enrich gram data graphs with js objects and primitives", | ||
"keywords": [ | ||
@@ -8,3 +9,3 @@ "graph", | ||
], | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"license": "MIT", | ||
@@ -54,7 +55,7 @@ "repository": { | ||
"devDependencies": { | ||
"@gram-data/gram-builder": "^0.3.2", | ||
"@gram-data/gram-parse": "^0.3.3", | ||
"@types/jest": "^26.0.16", | ||
"@gram-data/gram-builder": "^0.3.4", | ||
"@gram-data/gram-parse": "^0.3.4", | ||
"@types/jest": "^26.0.18", | ||
"@types/unist": "^2.0.3", | ||
"@typescript-eslint/parser": "^4.9.0", | ||
"@typescript-eslint/parser": "^4.9.1", | ||
"husky": "^4.3.5", | ||
@@ -72,3 +73,3 @@ "npm-check-updates": "^10.2.3", | ||
"dependencies": { | ||
"@gram-data/gram-ast": "^0.3.2", | ||
"@gram-data/gram-ast": "^0.3.4", | ||
"unified": "^9.2.0", | ||
@@ -80,3 +81,3 @@ "unist-util-visit": "^2.0.3" | ||
}, | ||
"gitHead": "4968a0ac1569f0bab127c1c991ccf5314e306670" | ||
"gitHead": "27de40df779bc903e8873563db12f7db477e4ad3" | ||
} |
import { | ||
BooleanLiteral, | ||
StringLiteral, | ||
TaggedLiteral, | ||
DateLiteral, | ||
@@ -18,2 +17,4 @@ IntegerLiteral, | ||
isGramRecord, | ||
GramRecord, | ||
TaggedTextLiteral | ||
} from '@gram-data/gram-ast'; | ||
@@ -60,8 +61,4 @@ | ||
*/ | ||
export const valueOf = (recordValue: GramRecordValue, literalValueEvaluator = valueOfLiteral): any => { | ||
if (isGramLiteralArray(recordValue)) { | ||
return recordValue.map((v: GramLiteral) => valueOf(v)); | ||
} else if (isLiteral(recordValue)) { | ||
return literalValueEvaluator(recordValue as GramLiteral); | ||
} else if (isGramRecord(recordValue)) { | ||
export const valueOf = (recordValue: GramRecordValue | GramRecord, literalValueEvaluator = valueOfLiteral): any => { | ||
if (isGramRecord(recordValue)) { | ||
return recordValue.reduce((acc, property) => { | ||
@@ -71,2 +68,10 @@ acc[property.name] = valueOf(property.value); | ||
}, {} as { [key: string]: any }); | ||
} else { | ||
if (isGramLiteralArray(recordValue)) { | ||
return recordValue.map((v: GramLiteral) => valueOf(v)); | ||
} else if (isLiteral(recordValue)) { | ||
return literalValueEvaluator(recordValue as GramLiteral); | ||
} else if (typeof recordValue === 'object') { | ||
return Object.entries(recordValue).reduce((acc, [k,v]) => {acc[k] = valueOf(v); return acc }, {} as { [key: string]: any }); | ||
} | ||
} | ||
@@ -95,4 +100,4 @@ }; | ||
switch (ast.tag) { | ||
case 'date': return valueOfDate(ast); | ||
case 'time': return valueOfTime(ast); | ||
case 'date': return valueOfDate(ast as DateLiteral); | ||
case 'time': return valueOfTime(ast as TimeLiteral); | ||
case 'datetime': return 'TODO'; | ||
@@ -103,3 +108,3 @@ case 'interval': return 'TODO'; | ||
case 'wkt': return 'TODO'; | ||
default: assertNever(ast); | ||
default: return 'TODO'; | ||
} | ||
@@ -123,3 +128,3 @@ case 'measurement': | ||
export const valueOfTaggedLiteral = (ast: TaggedLiteral) => { | ||
export const valueOfTaggedLiteral = (ast: TaggedTextLiteral) => { | ||
if (ast.value) { | ||
@@ -126,0 +131,0 @@ return ast.value; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
149473
1408
Updated@gram-data/gram-ast@^0.3.4