@gram-data/gram-value
Advanced tools
Comparing version 0.3.9 to 0.3.10
import { Plugin } from 'unified'; | ||
import { LiteralValueEvaluator } from './gram-value'; | ||
interface ValuePluginSettings { | ||
export interface ValuePluginSettings { | ||
literalValueEvaluator?: LiteralValueEvaluator; | ||
} | ||
declare const gramValuePlugin: Plugin<ValuePluginSettings[]>; | ||
export declare const gramValuePlugin: Plugin<ValuePluginSettings[]>; | ||
export default gramValuePlugin; |
@@ -5,3 +5,6 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var gramAst = require('@gram-data/gram-ast'); | ||
var visit = _interopDefault(require('unist-util-visit')); | ||
@@ -372,8 +375,5 @@ function _extends() { | ||
var visit = /*#__PURE__*/require('unist-util-visit'); | ||
var defaultSettings = { | ||
literalValueEvaluator: valueOfLiteral | ||
}; | ||
var gramValuePlugin = function gramValuePlugin(settings) { | ||
@@ -380,0 +380,0 @@ var s = _extends({}, defaultSettings, settings); |
@@ -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=/^([+-]\d{4,}\b|\d{4})$/,s=/^([0-9]{4})-(1[0-2]|0[1-9])$/,c=/^([0-9]{4})(-?)(1[0-2]|0[1-9])\2(3[01]|0[1-9]|[12][0-9])$/,l=/^(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]))?)?$/,f=/^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+)S)?)?$/,p=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)),v=function r(t,n){return void 0===n&&(n=m),e.isGramRecord(t)?Array.from(t).reduce((function(e,t){return e[t[0]]=r(t[1]),e}),{}):e.isGramLiteralArray(t)?t.map((function(e){return r(e)})):e.isGramLiteral(t)?n(t):"object"==typeof t?Object.entries(t).reduce((function(e,t){return e[t[0]]=r(t[1]),e}),{}):void 0},m=function(e){switch(e.type){case"boolean":return b(e);case"string":return d(e);case"integer":return O(e);case"decimal":return y(e);case"hexadecimal":return h(e);case"octal":return g(e);case"tagged":switch(e.tag){case"date":return w(e);case"time":return x(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)}},b=function(e){return e.value&&"true"===e.value.toLowerCase()},d=function(e){if(e.value)return e.value;throw new p(e)},w=function(e){if(e.value){var r=c.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=i.exec(e.value))return new Date(Number.parseInt(r[1]),1);throw SyntaxError("Unable to parse date from "+e.value)}throw new p(e)},x=function(e){if(e.value){var r=l.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 p(e)},O=function(e){if(e.value)return Number.parseInt(e.value);throw new p(e)},y=function(e){if(e.value)return Number.parseFloat(e.value);throw new p(e)},h=function(e){if(e.value)return Number.parseInt(e.value,16);throw new p(e)},g=function(e){if(e.value)return Number.parseInt(e.value,8);throw new p(e)},N=require("unist-util-visit"),I={literalValueEvaluator:m};exports.gramValuePlugin=function(t){var n=r({},I,t);return function(r){N(r,(function(r){e.isGramPath(r)&&r.record&&(r.data=Object.assign(r.data||{},{value:v(r.record,n.literalValueEvaluator)}))}))}},exports.iso8601Duration=f,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=l,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=i,exports.iso8601YearMonth=s,exports.iso8601YearMonthDay=c,exports.valueOf=v,exports.valueOfBoolean=b,exports.valueOfDate=w,exports.valueOfDecimal=y,exports.valueOfDuration=function(e){if(e.value){var r=f.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 p(e)},exports.valueOfHexadecimal=h,exports.valueOfInteger=O,exports.valueOfLiteral=m,exports.valueOfMeasurement=function(e){if(e.value)return Number.parseInt(e.value);throw new p(e)},exports.valueOfOctal=g,exports.valueOfString=d,exports.valueOfTaggedLiteral=function(e){if(e.value)return e.value;throw new p(e)},exports.valueOfTime=x; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("@gram-data/gram-ast"),t=(e=require("unist-util-visit"))&&"object"==typeof e&&"default"in e?e.default:e;function n(){return(n=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 a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,r){return(u=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function o(){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 i(e,r,t){return(i=o()?Reflect.construct:function(e,r,t){var n=[null];n.push.apply(n,r);var a=new(Function.bind.apply(e,n));return t&&u(a,t.prototype),a}).apply(null,arguments)}function s(e){var r="function"==typeof Map?new Map:void 0;return(s=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,t)}function t(){return i(e,arguments,a(this).constructor)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),u(t,e)})(e)}var 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}(s(Error)),b=function e(t,n){return void 0===n&&(n=d),r.isGramRecord(t)?Array.from(t).reduce((function(r,t){return r[t[0]]=e(t[1]),r}),{}):r.isGramLiteralArray(t)?t.map((function(r){return e(r)})):r.isGramLiteral(t)?n(t):"object"==typeof t?Object.entries(t).reduce((function(r,t){return r[t[0]]=e(t[1]),r}),{}):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)},D={literalValueEvaluator:d};exports.gramValuePlugin=function(e){var a=n({},D,e);return function(e){t(e,(function(e){r.isGramPath(e)&&e.record&&(e.data=Object.assign(e.data||{},{value:b(e.record,a.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 |
import { isGramRecord, isGramLiteralArray, isGramLiteral, isGramPath } from '@gram-data/gram-ast'; | ||
import visit from 'unist-util-visit'; | ||
@@ -367,8 +368,5 @@ function _extends() { | ||
var visit = /*#__PURE__*/require('unist-util-visit'); | ||
var defaultSettings = { | ||
literalValueEvaluator: valueOfLiteral | ||
}; | ||
var gramValuePlugin = function gramValuePlugin(settings) { | ||
@@ -375,0 +373,0 @@ var s = _extends({}, defaultSettings, settings); |
@@ -408,8 +408,206 @@ (function (global, factory) { | ||
var visit = /*#__PURE__*/require('unist-util-visit'); | ||
var convert_1 = convert; | ||
function convert(test) { | ||
if (test == null) { | ||
return ok | ||
} | ||
if (typeof test === 'string') { | ||
return typeFactory(test) | ||
} | ||
if (typeof test === 'object') { | ||
return 'length' in test ? anyFactory(test) : allFactory(test) | ||
} | ||
if (typeof test === 'function') { | ||
return test | ||
} | ||
throw new Error('Expected function, string, or object as test') | ||
} | ||
// Utility assert each property in `test` is represented in `node`, and each | ||
// values are strictly equal. | ||
function allFactory(test) { | ||
return all | ||
function all(node) { | ||
var key; | ||
for (key in test) { | ||
if (node[key] !== test[key]) return false | ||
} | ||
return true | ||
} | ||
} | ||
function anyFactory(tests) { | ||
var checks = []; | ||
var index = -1; | ||
while (++index < tests.length) { | ||
checks[index] = convert(tests[index]); | ||
} | ||
return any | ||
function any() { | ||
var index = -1; | ||
while (++index < checks.length) { | ||
if (checks[index].apply(this, arguments)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
} | ||
// Utility to convert a string into a function which checks a given node’s type | ||
// for said string. | ||
function typeFactory(test) { | ||
return type | ||
function type(node) { | ||
return Boolean(node && node.type === test) | ||
} | ||
} | ||
// Utility to return true. | ||
function ok() { | ||
return true | ||
} | ||
var color_browser = identity; | ||
function identity(d) { | ||
return d | ||
} | ||
var unistUtilVisitParents = visitParents; | ||
var CONTINUE = true; | ||
var SKIP = 'skip'; | ||
var EXIT = false; | ||
visitParents.CONTINUE = CONTINUE; | ||
visitParents.SKIP = SKIP; | ||
visitParents.EXIT = EXIT; | ||
function visitParents(tree, test, visitor, reverse) { | ||
var step; | ||
var is; | ||
if (typeof test === 'function' && typeof visitor !== 'function') { | ||
reverse = visitor; | ||
visitor = test; | ||
test = null; | ||
} | ||
is = convert_1(test); | ||
step = reverse ? -1 : 1; | ||
factory(tree, null, [])(); | ||
function factory(node, index, parents) { | ||
var value = typeof node === 'object' && node !== null ? node : {}; | ||
var name; | ||
if (typeof value.type === 'string') { | ||
name = | ||
typeof value.tagName === 'string' | ||
? value.tagName | ||
: typeof value.name === 'string' | ||
? value.name | ||
: undefined; | ||
visit.displayName = | ||
'node (' + color_browser(value.type + (name ? '<' + name + '>' : '')) + ')'; | ||
} | ||
return visit | ||
function visit() { | ||
var grandparents = parents.concat(node); | ||
var result = []; | ||
var subresult; | ||
var offset; | ||
if (!test || is(node, index, parents[parents.length - 1] || null)) { | ||
result = toResult(visitor(node, parents)); | ||
if (result[0] === EXIT) { | ||
return result | ||
} | ||
} | ||
if (node.children && result[0] !== SKIP) { | ||
offset = (reverse ? node.children.length : -1) + step; | ||
while (offset > -1 && offset < node.children.length) { | ||
subresult = factory(node.children[offset], offset, grandparents)(); | ||
if (subresult[0] === EXIT) { | ||
return subresult | ||
} | ||
offset = | ||
typeof subresult[1] === 'number' ? subresult[1] : offset + step; | ||
} | ||
} | ||
return result | ||
} | ||
} | ||
} | ||
function toResult(value) { | ||
if (value !== null && typeof value === 'object' && 'length' in value) { | ||
return value | ||
} | ||
if (typeof value === 'number') { | ||
return [CONTINUE, value] | ||
} | ||
return [value] | ||
} | ||
var unistUtilVisit = visit; | ||
var CONTINUE$1 = unistUtilVisitParents.CONTINUE; | ||
var SKIP$1 = unistUtilVisitParents.SKIP; | ||
var EXIT$1 = unistUtilVisitParents.EXIT; | ||
visit.CONTINUE = CONTINUE$1; | ||
visit.SKIP = SKIP$1; | ||
visit.EXIT = EXIT$1; | ||
function visit(tree, test, visitor, reverse) { | ||
if (typeof test === 'function' && typeof visitor !== 'function') { | ||
reverse = visitor; | ||
visitor = test; | ||
test = null; | ||
} | ||
unistUtilVisitParents(tree, test, overload, reverse); | ||
function overload(node, parents) { | ||
var parent = parents[parents.length - 1]; | ||
var index = parent ? parent.children.indexOf(node) : null; | ||
return visitor(node, index, parent) | ||
} | ||
} | ||
var defaultSettings = { | ||
literalValueEvaluator: valueOfLiteral | ||
}; | ||
var gramValuePlugin = function gramValuePlugin(settings) { | ||
@@ -419,3 +617,3 @@ var s = _extends({}, defaultSettings, settings); | ||
var recordValueEvaluator = function recordValueEvaluator(tree) { | ||
visit(tree, function (element) { | ||
unistUtilVisit(tree, function (element) { | ||
if (isGramPath(element) && element.record) { | ||
@@ -422,0 +620,0 @@ element.data = Object.assign(element.data || {}, { |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e=e||self).gram=e.gram||{},e.gram.value={}))}(this,(function(e){"use strict";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}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,t,r){return(u=a()?Reflect.construct:function(e,t,r){var a=[null];a.push.apply(a,t);var u=new(Function.bind.apply(e,a));return r&&n(u,r.prototype),u}).apply(null,arguments)}function o(e){var t="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!==t){if(t.has(e))return t.get(e);t.set(e,a)}function a(){return u(e,arguments,r(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=/^([+-]\d{4,}\b|\d{4})$/,f=/^([0-9]{4})-(1[0-2]|0[1-9])$/,l=/^([0-9]{4})(-?)(1[0-2]|0[1-9])\2(3[01]|0[1-9]|[12][0-9])$/,s=/^(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]))?)?$/,p=/^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+)S)?)?$/,v=function(e){var t,r;function n(t){var r;return(r=e.call(this,"AST is invalid:"+JSON.stringify(t))||this).name="InvalidAstError",r.ast=t,r}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n}(o(Error)),m=function e(t,r){return void 0===r&&(r=d),"object"==typeof(n=t)&&n instanceof Map?Array.from(t).reduce((function(t,r){return t[r[0]]=e(r[1]),t}),{}):function(e){return Array.isArray(e)&&i(e[0])}(t)?t.map((function(t){return e(t)})):i(t)?r(t):"object"==typeof t?Object.entries(t).reduce((function(t,r){return t[r[0]]=e(r[1]),t}),{}):void 0;var n},d=function(e){switch(e.type){case"boolean":return b(e);case"string":return y(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 w(e);case"time":return O(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)}},b=function(e){return e.value&&"true"===e.value.toLowerCase()},y=function(e){if(e.value)return e.value;throw new v(e)},w=function(e){if(e.value){var t=l.exec(e.value);if(t)return new Date(Date.UTC(Number.parseInt(t[1]),Number.parseInt(t[3])-1,Number.parseInt(t[4])));if(t=f.exec(e.value))return new Date(Date.UTC(Number.parseInt(t[1]),Number.parseInt(t[2])));if(t=c.exec(e.value))return new Date(Number.parseInt(t[1]),1);throw SyntaxError("Unable to parse date from "+e.value)}throw new v(e)},O=function(e){if(e.value){var t=s.exec(e.value);if(t){var r=Number.parseInt(t[1]),n=t[1]?Number.parseInt(t[2]):0,a=t[3]?Number.parseFloat(t[3]):0,u=t[5],o=36e5*r+6e4*n+1e3*a;if(u){var i="Z"===u?0:36e5*Number.parseInt(t[7])+6e4*Number.parseInt(t[8]||"0");return new Date("-"===t[6]?o+i:o-i)}return new Date(o)}throw SyntaxError("Unable to parse time from "+e.value)}throw new v(e)},h=function(e){if(e.value)return Number.parseInt(e.value);throw new v(e)},g=function(e){if(e.value)return Number.parseFloat(e.value);throw new v(e)},N=function(e){if(e.value)return Number.parseInt(e.value,16);throw new v(e)},I=function(e){if(e.value)return Number.parseInt(e.value,8);throw new v(e)},D=require("unist-util-visit"),x={literalValueEvaluator:d};e.gramValuePlugin=function(e){var r=t({},x,e);return function(e){D(e,(function(e){var t;(t=e).type&&"path"===t.type&&e.record&&(e.data=Object.assign(e.data||{},{value:m(e.record,r.literalValueEvaluator)}))}))}},e.iso8601Duration=p,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=s,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=c,e.iso8601YearMonth=f,e.iso8601YearMonthDay=l,e.valueOf=m,e.valueOfBoolean=b,e.valueOfDate=w,e.valueOfDecimal=g,e.valueOfDuration=function(e){if(e.value){var t=p.exec(e.value);if(t){var r=t[2]?Number.parseInt(t[2]):0,n=t[4]?Number.parseInt(t[4]):0,a=t[6]?Number.parseInt(t[6]):0,u=t[9]?Number.parseInt(t[9]):0,o=t[11]?Number.parseInt(t[11]):0,i=t[13]?Number.parseInt(t[13]):0;return new Date(31536e6*r+2592e6*n+864e5*a+36e5*u+6e4*o+1e3*i)}throw SyntaxError("Unable to parse duration from "+e.value)}throw new v(e)},e.valueOfHexadecimal=N,e.valueOfInteger=h,e.valueOfLiteral=d,e.valueOfMeasurement=function(e){if(e.value)return Number.parseInt(e.value);throw new v(e)},e.valueOfOctal=I,e.valueOfString=y,e.valueOfTaggedLiteral=function(e){if(e.value)return e.value;throw new v(e)},e.valueOfTime=O,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e=e||self).gram=e.gram||{},e.gram.value={}))}(this,(function(e){"use strict";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(){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 a(e,t,r){return(a=u()?Reflect.construct:function(e,t,r){var u=[null];u.push.apply(u,t);var a=new(Function.bind.apply(e,u));return r&&n(a,r.prototype),a}).apply(null,arguments)}function o(e){var t="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!==t){if(t.has(e))return t.get(e);t.set(e,u)}function u(){return a(e,arguments,r(this).constructor)}return u.prototype=Object.create(e.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),n(u,e)})(e)}var i=function(e){return!!e.type&&!!e.value&&"property"!==e.type},f=/^([+-]\d{4,}\b|\d{4})$/,c=/^([0-9]{4})-(1[0-2]|0[1-9])$/,l=/^([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]))?)?$/,s=/^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+)S)?)?$/,v=function(e){var t,r;function n(t){var r;return(r=e.call(this,"AST is invalid:"+JSON.stringify(t))||this).name="InvalidAstError",r.ast=t,r}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n}(o(Error)),y=function e(t,r){return void 0===r&&(r=d),"object"==typeof(n=t)&&n instanceof Map?Array.from(t).reduce((function(t,r){return t[r[0]]=e(r[1]),t}),{}):function(e){return Array.isArray(e)&&i(e[0])}(t)?t.map((function(t){return e(t)})):i(t)?r(t):"object"==typeof t?Object.entries(t).reduce((function(t,r){return t[r[0]]=e(r[1]),t}),{}):void 0;var n},d=function(e){switch(e.type){case"boolean":return m(e);case"string":return b(e);case"integer":return O(e);case"decimal":return g(e);case"hexadecimal":return N(e);case"octal":return I(e);case"tagged":switch(e.tag){case"date":return h(e);case"time":return w(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)}},m=function(e){return e.value&&"true"===e.value.toLowerCase()},b=function(e){if(e.value)return e.value;throw new v(e)},h=function(e){if(e.value){var t=l.exec(e.value);if(t)return new Date(Date.UTC(Number.parseInt(t[1]),Number.parseInt(t[3])-1,Number.parseInt(t[4])));if(t=c.exec(e.value))return new Date(Date.UTC(Number.parseInt(t[1]),Number.parseInt(t[2])));if(t=f.exec(e.value))return new Date(Number.parseInt(t[1]),1);throw SyntaxError("Unable to parse date from "+e.value)}throw new v(e)},w=function(e){if(e.value){var t=p.exec(e.value);if(t){var r=Number.parseInt(t[1]),n=t[1]?Number.parseInt(t[2]):0,u=t[3]?Number.parseFloat(t[3]):0,a=t[5],o=36e5*r+6e4*n+1e3*u;if(a){var i="Z"===a?0:36e5*Number.parseInt(t[7])+6e4*Number.parseInt(t[8]||"0");return new Date("-"===t[6]?o+i:o-i)}return new Date(o)}throw SyntaxError("Unable to parse time from "+e.value)}throw new v(e)},O=function(e){if(e.value)return Number.parseInt(e.value);throw new v(e)},g=function(e){if(e.value)return Number.parseFloat(e.value);throw new v(e)},N=function(e){if(e.value)return Number.parseInt(e.value,16);throw new v(e)},I=function(e){if(e.value)return Number.parseInt(e.value,8);throw new v(e)};function D(){return!0}var j=x;function x(e,t,r,n){var u,a;"function"==typeof t&&"function"!=typeof r&&(n=r,r=t,t=null),a=function e(t){if(null==t)return D;if("string"==typeof t)return function(e){return function(t){return Boolean(t&&t.type===e)}}(t);if("object"==typeof t)return"length"in t?function(t){for(var r=[],n=-1;++n<t.length;)r[n]=e(t[n]);return function(){for(var e=-1;++e<r.length;)if(r[e].apply(this,arguments))return!0;return!1}}(t):function(e){return function(t){var r;for(r in e)if(t[r]!==e[r])return!1;return!0}}(t);if("function"==typeof t)return t;throw new Error("Expected function, string, or object as test")}(t),u=n?-1:1,function e(o,i,f){var c,l="object"==typeof o&&null!==o?o:{};return"string"==typeof l.type&&(p.displayName="node ("+l.type+((c="string"==typeof l.tagName?l.tagName:"string"==typeof l.name?l.name:void 0)?"<"+c+">":"")+")"),p;function p(){var c,l,p=f.concat(o),s=[];if((!t||a(o,i,f[f.length-1]||null))&&!1===(s=function(e){return null!==e&&"object"==typeof e&&"length"in e?e:"number"==typeof e?[!0,e]:[e]}(r(o,f)))[0])return s;if(o.children&&"skip"!==s[0])for(l=(n?o.children.length:-1)+u;l>-1&&l<o.children.length;){if(!1===(c=e(o.children[l],l,p)())[0])return c;l="number"==typeof c[1]?c[1]:l+u}return s}}(e,null,[])()}x.CONTINUE=!0,x.SKIP="skip",x.EXIT=!1;var E=S,T=j.SKIP,_=j.EXIT;function S(e,t,r,n){"function"==typeof t&&"function"!=typeof r&&(n=r,r=t,t=null),j(e,t,(function(e,t){var n=t[t.length-1],u=n?n.children.indexOf(e):null;return r(e,u,n)}),n)}S.CONTINUE=j.CONTINUE,S.SKIP=T,S.EXIT=_;var P={literalValueEvaluator:d};e.gramValuePlugin=function(e){var r=t({},P,e);return function(e){E(e,(function(e){var t;(t=e).type&&"path"===t.type&&e.record&&(e.data=Object.assign(e.data||{},{value:y(e.record,r.literalValueEvaluator)}))}))}},e.iso8601Duration=s,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=p,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=f,e.iso8601YearMonth=c,e.iso8601YearMonthDay=l,e.valueOf=y,e.valueOfBoolean=m,e.valueOfDate=h,e.valueOfDecimal=g,e.valueOfDuration=function(e){if(e.value){var t=s.exec(e.value);if(t){var r=t[2]?Number.parseInt(t[2]):0,n=t[4]?Number.parseInt(t[4]):0,u=t[6]?Number.parseInt(t[6]):0,a=t[9]?Number.parseInt(t[9]):0,o=t[11]?Number.parseInt(t[11]):0,i=t[13]?Number.parseInt(t[13]):0;return new Date(31536e6*r+2592e6*n+864e5*u+36e5*a+6e4*o+1e3*i)}throw SyntaxError("Unable to parse duration from "+e.value)}throw new v(e)},e.valueOfHexadecimal=N,e.valueOfInteger=O,e.valueOfLiteral=d,e.valueOfMeasurement=function(e){if(e.value)return Number.parseInt(e.value);throw new v(e)},e.valueOfOctal=I,e.valueOfString=b,e.valueOfTaggedLiteral=function(e){if(e.value)return e.value;throw new v(e)},e.valueOfTime=w,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=gram-value.umd.production.min.js.map |
@@ -1,3 +0,2 @@ | ||
import gramValuePlugin from './gram-value-plugin'; | ||
export { gramValuePlugin, ValuePluginSettings } from './gram-value-plugin'; | ||
export * from './gram-value'; | ||
export { gramValuePlugin }; |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"license": "MIT", | ||
@@ -55,4 +55,4 @@ "repository": { | ||
"devDependencies": { | ||
"@gram-data/gram-builder": "^0.3.9", | ||
"@gram-data/gram-parse": "^0.3.9", | ||
"@gram-data/gram-builder": "^0.3.10", | ||
"@gram-data/gram-parse": "^0.3.10", | ||
"@types/jest": "^26.0.19", | ||
@@ -73,3 +73,3 @@ "@types/unist": "^2.0.3", | ||
"dependencies": { | ||
"@gram-data/gram-ast": "^0.3.9", | ||
"@gram-data/gram-ast": "^0.3.10", | ||
"unified": "^9.2.0", | ||
@@ -81,3 +81,3 @@ "unist-util-visit": "^2.0.3" | ||
}, | ||
"gitHead": "f77b8ca02cfafdf66e58eb67632ba8ad9857d3f2" | ||
"gitHead": "9cff6b85ef35c39a0c4cae074def39ed4a4c84b7" | ||
} |
@@ -7,5 +7,5 @@ import { Plugin, Transformer } from 'unified'; | ||
const visit = require('unist-util-visit'); | ||
import visit from 'unist-util-visit'; | ||
interface ValuePluginSettings { | ||
export interface ValuePluginSettings { | ||
literalValueEvaluator?: LiteralValueEvaluator; | ||
@@ -18,3 +18,3 @@ } | ||
const gramValuePlugin: Plugin<ValuePluginSettings[]> = ( | ||
export const gramValuePlugin: Plugin<ValuePluginSettings[]> = ( | ||
settings: ValuePluginSettings | ||
@@ -21,0 +21,0 @@ ) => { |
@@ -1,5 +0,3 @@ | ||
import gramValuePlugin from './gram-value-plugin'; | ||
export { gramValuePlugin, ValuePluginSettings } from './gram-value-plugin'; | ||
export * from './gram-value'; | ||
export { gramValuePlugin }; |
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
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
172273
1577
3
Updated@gram-data/gram-ast@^0.3.10