@getlang/lib
Advanced tools
Comparing version 0.0.15 to 0.0.16
import * as scp from 'set-cookie-parser'; | ||
import { NullSelection } from '@getlang/utils'; | ||
export declare const parse: (source: string) => scp.CookieMap; | ||
export declare const select: (cookies: scp.CookieMap, selector: string, expand: boolean) => string | undefined; | ||
export declare const select: (cookies: scp.CookieMap, selector: string, expand: boolean) => string | NullSelection; | ||
export declare const toValue: (cookies: scp.CookieMap) => { | ||
[x: string]: string; | ||
}; |
import * as scp from 'set-cookie-parser'; | ||
import { mapValues } from 'lodash-es'; | ||
import { QuerySyntaxError, invariant } from '@getlang/utils'; | ||
import { QuerySyntaxError, invariant, NullSelection } from '@getlang/utils'; | ||
export const parse = (source) => { | ||
@@ -10,3 +10,3 @@ const cookie = scp.splitCookiesString(source); | ||
invariant(!expand, new QuerySyntaxError('Cannot expand cookies selector')); | ||
return cookies[selector]?.value; | ||
return cookies[selector]?.value ?? new NullSelection(selector); | ||
}; | ||
@@ -13,0 +13,0 @@ export const toValue = (cookies) => { |
@@ -1,4 +0,5 @@ | ||
export declare const select: (headers: Headers, selector: string, expand: boolean) => string | string[] | undefined; | ||
import { NullSelection } from '@getlang/utils'; | ||
export declare const select: (headers: Headers, selector: string, expand: boolean) => string | NullSelection | string[]; | ||
export declare const toValue: (headers: Headers) => { | ||
[k: string]: string; | ||
}; |
@@ -0,1 +1,2 @@ | ||
import { NullSelection } from '@getlang/utils'; | ||
export const select = (headers, selector, expand) => { | ||
@@ -9,3 +10,3 @@ if (expand && selector === 'set-cookie') { | ||
} | ||
return result === null ? undefined : result; | ||
return result === null ? new NullSelection(selector) : result; | ||
}; | ||
@@ -12,0 +13,0 @@ export const toValue = (headers) => { |
import type { AnyHtmlNode } from 'domhandler'; | ||
import { NullSelection } from '@getlang/utils'; | ||
import './html/patch-dom.js'; | ||
export declare const parse: (html: string) => AnyHtmlNode; | ||
export declare const select: (el: AnyHtmlNode, selector: string, expand: boolean) => AnyHtmlNode | AnyHtmlNode[] | undefined; | ||
export declare const select: (el: AnyHtmlNode, selector: string, expand: boolean) => NullSelection | AnyHtmlNode | AnyHtmlNode[] | undefined; | ||
export declare const toValue: (el: AnyHtmlNode) => string; |
@@ -8,3 +8,3 @@ /// <reference types="./html/types.d.ts" /> | ||
import { parse as parseCss } from 'css-what'; | ||
import { SelectorSyntaxError, NullSelectionError, invariant, } from '@getlang/utils'; | ||
import { SelectorSyntaxError, NullSelectionError, invariant, NullSelection, } from '@getlang/utils'; | ||
import './html/patch-dom.js'; | ||
@@ -33,3 +33,3 @@ export const parse = (html) => { | ||
} | ||
return result.length ? result[0] : undefined; | ||
return result.length ? result[0] : new NullSelection(selector); | ||
}; | ||
@@ -47,3 +47,3 @@ const selectCss = (el, selector, expand) => { | ||
} | ||
return result === null ? undefined : result; | ||
return result === null ? new NullSelection(selector) : result; | ||
}; | ||
@@ -50,0 +50,0 @@ export const select = (el, selector, expand) => { |
@@ -1,9 +0,4 @@ | ||
import { compareDocumentPosition } from 'domutils'; | ||
import ds from 'dom-serializer'; | ||
import { Node, Element } from 'domhandler'; | ||
function main() { | ||
; | ||
Node.prototype.compareDocumentPosition = function (other) { | ||
return compareDocumentPosition(this, other); | ||
}; | ||
Element.prototype.toString = function () { | ||
@@ -10,0 +5,0 @@ return ds(this); |
import type { AnyNode } from 'acorn'; | ||
import { NullSelection } from '@getlang/utils'; | ||
export declare const parse: (js: string) => AnyNode; | ||
export declare const select: (node: AnyNode, selector: string, expand: boolean) => import("estree").Program | import("estree").Property | import("estree").CatchClause | import("estree").ClassDeclaration | import("estree").ClassExpression | import("estree").ClassBody | import("estree").Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").BigIntLiteral | import("estree").ArrayExpression | import("estree").ArrowFunctionExpression | import("estree").AssignmentExpression | import("estree").AwaitExpression | import("estree").BinaryExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").ChainExpression | import("estree").ConditionalExpression | import("estree").FunctionExpression | import("estree").ImportExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").MetaProperty | import("estree").ObjectExpression | import("estree").SequenceExpression | import("estree").TaggedTemplateExpression | import("estree").TemplateLiteral | import("estree").ThisExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").YieldExpression | import("estree").FunctionDeclaration | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").PrivateIdentifier | import("estree").PropertyDefinition | import("estree").SpreadElement | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").StaticBlock | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").Super | import("estree").SwitchCase | import("estree").TemplateElement | import("estree").VariableDeclarator | import("estree").Node[] | undefined; | ||
export declare const select: (node: AnyNode, selector: string, expand: boolean) => NullSelection | import("estree").Program | import("estree").Property | import("estree").CatchClause | import("estree").ClassDeclaration | import("estree").ClassExpression | import("estree").ClassBody | import("estree").Identifier | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").BigIntLiteral | import("estree").ArrayExpression | import("estree").ArrowFunctionExpression | import("estree").AssignmentExpression | import("estree").AwaitExpression | import("estree").BinaryExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").ChainExpression | import("estree").ConditionalExpression | import("estree").FunctionExpression | import("estree").ImportExpression | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").MetaProperty | import("estree").ObjectExpression | import("estree").SequenceExpression | import("estree").TaggedTemplateExpression | import("estree").TemplateLiteral | import("estree").ThisExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").YieldExpression | import("estree").FunctionDeclaration | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").PrivateIdentifier | import("estree").PropertyDefinition | import("estree").SpreadElement | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").StaticBlock | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").Super | import("estree").SwitchCase | import("estree").TemplateElement | import("estree").VariableDeclarator | import("estree").Node[] | undefined; | ||
export declare const toValue: (node: AnyNode) => string | number | bigint | boolean | RegExp | null | undefined; |
import { parse as acorn } from 'acorn'; | ||
import esquery from 'esquery'; | ||
import { SelectorSyntaxError, ConversionError, invariant } from '@getlang/utils'; | ||
import { SelectorSyntaxError, ConversionError, invariant, NullSelection, } from '@getlang/utils'; | ||
export const parse = (js) => { | ||
@@ -13,3 +13,3 @@ return acorn(js, { ecmaVersion: 'latest' }); | ||
} | ||
return matches.length ? matches[0] : undefined; | ||
return matches.length ? matches[0] : new NullSelection(selector); | ||
} | ||
@@ -16,0 +16,0 @@ catch (e) { |
import { get } from 'lodash-es'; | ||
import { NullSelection } from '@getlang/utils'; | ||
export const parse = (json) => JSON.parse(json); | ||
@@ -7,4 +8,4 @@ // only an `undefined` result is considered a null selection | ||
export const select = (value, selector, expand) => { | ||
return get(value, selector, expand ? [] : undefined); | ||
return get(value, selector, expand ? [] : new NullSelection(selector)); | ||
}; | ||
//# sourceMappingURL=json.js.map |
{ | ||
"name": "@getlang/lib", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "type": "module", |
import * as scp from 'set-cookie-parser' | ||
import { mapValues } from 'lodash-es' | ||
import { QuerySyntaxError, invariant } from '@getlang/utils' | ||
import { QuerySyntaxError, invariant, NullSelection } from '@getlang/utils' | ||
@@ -16,3 +16,3 @@ export const parse = (source: string) => { | ||
invariant(!expand, new QuerySyntaxError('Cannot expand cookies selector')) | ||
return cookies[selector]?.value | ||
return cookies[selector]?.value ?? new NullSelection(selector) | ||
} | ||
@@ -19,0 +19,0 @@ |
@@ -0,1 +1,3 @@ | ||
import { NullSelection } from '@getlang/utils' | ||
export const select = (headers: Headers, selector: string, expand: boolean) => { | ||
@@ -9,3 +11,3 @@ if (expand && selector === 'set-cookie') { | ||
} | ||
return result === null ? undefined : result | ||
return result === null ? new NullSelection(selector) : result | ||
} | ||
@@ -12,0 +14,0 @@ |
@@ -14,2 +14,3 @@ /// <reference types="./html/types.d.ts" /> | ||
invariant, | ||
NullSelection, | ||
} from '@getlang/utils' | ||
@@ -42,3 +43,3 @@ import './html/patch-dom.js' | ||
} | ||
return result.length ? result[0] : undefined | ||
return result.length ? result[0] : new NullSelection(selector) | ||
} | ||
@@ -56,3 +57,3 @@ | ||
} | ||
return result === null ? undefined : result | ||
return result === null ? new NullSelection(selector) : result | ||
} | ||
@@ -59,0 +60,0 @@ |
// @sideEffects | ||
import type { ElementType } from 'domelementtype' | ||
import { compareDocumentPosition } from 'domutils' | ||
import ds from 'dom-serializer' | ||
@@ -19,6 +18,2 @@ import type { AnyNode } from 'domhandler' | ||
function main() { | ||
;(Node.prototype as any).compareDocumentPosition = function (other: AnyNode) { | ||
return compareDocumentPosition(this, other) | ||
} | ||
Element.prototype.toString = function () { | ||
@@ -25,0 +20,0 @@ return ds(this) |
import { parse as acorn } from 'acorn' | ||
import type { AnyNode } from 'acorn' | ||
import esquery from 'esquery' | ||
import { SelectorSyntaxError, ConversionError, invariant } from '@getlang/utils' | ||
import { | ||
SelectorSyntaxError, | ||
ConversionError, | ||
invariant, | ||
NullSelection, | ||
} from '@getlang/utils' | ||
@@ -16,3 +21,3 @@ export const parse = (js: string): AnyNode => { | ||
} | ||
return matches.length ? matches[0] : undefined | ||
return matches.length ? matches[0] : new NullSelection(selector) | ||
} catch (e: any) { | ||
@@ -19,0 +24,0 @@ invariant( |
import { get } from 'lodash-es' | ||
import { NullSelection } from '@getlang/utils' | ||
@@ -9,3 +10,3 @@ export const parse = (json: string) => JSON.parse(json) | ||
export const select = (value: any, selector: string, expand: boolean) => { | ||
return get(value, selector, expand ? [] : undefined) | ||
return get(value, selector, expand ? [] : new NullSelection(selector)) | ||
} |
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
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
34914
641