@getlang/lib
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -1,6 +0,7 @@ | ||
import { SliceError } from '@getlang/utils'; | ||
import { SliceError, NullSelection } from '@getlang/utils'; | ||
export const runSlice = async (slice, context = {}, raw = {}) => { | ||
try { | ||
const fn = new Function('$', '$$', slice); | ||
return await fn(context, raw); | ||
const value = await fn(context, raw); | ||
return value === undefined ? new NullSelection('<slice>') : value; | ||
} | ||
@@ -7,0 +8,0 @@ catch (e) { |
@@ -6,7 +6,7 @@ import { NullSelection } from '@getlang/utils'; | ||
} | ||
const result = headers.get(selector); | ||
const value = headers.get(selector); | ||
if (expand) { | ||
return result ? result.split(',').map(x => x.trimStart()) : []; | ||
return value ? value.split(',').map(x => x.trimStart()) : []; | ||
} | ||
return result === null ? new NullSelection(selector) : result; | ||
return value === null ? new NullSelection(selector) : value; | ||
}; | ||
@@ -13,0 +13,0 @@ export const toValue = (headers) => { |
@@ -28,7 +28,7 @@ /// <reference types="./html/types.d.ts" /> | ||
} | ||
const result = xpath.select(selector, root); | ||
const value = xpath.select(selector, root); | ||
if (expand) { | ||
return result; | ||
return value; | ||
} | ||
return result.length ? result[0] : new NullSelection(selector); | ||
return value.length ? value[0] : new NullSelection(selector); | ||
}; | ||
@@ -42,7 +42,7 @@ const selectCss = (el, selector, expand) => { | ||
} | ||
const result = expand ? selectAll(selector, el) : selectOne(selector, el); | ||
const value = expand ? selectAll(selector, el) : selectOne(selector, el); | ||
if (expand) { | ||
return result ?? []; | ||
return value ?? []; | ||
} | ||
return result === null ? new NullSelection(selector) : result; | ||
return value === null ? new NullSelection(selector) : value; | ||
}; | ||
@@ -49,0 +49,0 @@ export const select = (el, selector, expand) => { |
{ | ||
"name": "@getlang/lib", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -1,2 +0,2 @@ | ||
import { SliceError } from '@getlang/utils' | ||
import { SliceError, NullSelection } from '@getlang/utils' | ||
@@ -10,3 +10,4 @@ export const runSlice = async ( | ||
const fn = new Function('$', '$$', slice) | ||
return await fn(context, raw) | ||
const value = await fn(context, raw) | ||
return value === undefined ? new NullSelection('<slice>') : value | ||
} catch (e) { | ||
@@ -13,0 +14,0 @@ throw new SliceError({ cause: e }) |
@@ -7,7 +7,7 @@ import { NullSelection } from '@getlang/utils' | ||
} | ||
const result = headers.get(selector) | ||
const value = headers.get(selector) | ||
if (expand) { | ||
return result ? result.split(',').map(x => x.trimStart()) : [] | ||
return value ? value.split(',').map(x => x.trimStart()) : [] | ||
} | ||
return result === null ? new NullSelection(selector) : result | ||
return value === null ? new NullSelection(selector) : value | ||
} | ||
@@ -14,0 +14,0 @@ |
@@ -38,7 +38,7 @@ /// <reference types="./html/types.d.ts" /> | ||
const result = xpath.select(selector, root) | ||
const value = xpath.select(selector, root) | ||
if (expand) { | ||
return result | ||
return value | ||
} | ||
return result.length ? result[0] : new NullSelection(selector) | ||
return value.length ? value[0] : new NullSelection(selector) | ||
} | ||
@@ -52,7 +52,7 @@ | ||
} | ||
const result = expand ? selectAll(selector, el) : selectOne(selector, el) | ||
const value = expand ? selectAll(selector, el) : selectOne(selector, el) | ||
if (expand) { | ||
return result ?? [] | ||
return value ?? [] | ||
} | ||
return result === null ? new NullSelection(selector) : result | ||
return value === null ? new NullSelection(selector) : value | ||
} | ||
@@ -59,0 +59,0 @@ |
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
35188
643