# query-by-name-path

> query dom element by name attribute path

Latest version **1.0.1** (published 2021-11-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install query-by-name-path
pnpm add query-by-name-path
yarn add query-by-name-path
bun add query-by-name-path
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-11-06 |
| First published | 2021-11-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | fwg |
| Maintainers | adf0001 |
| Keywords | query, attribute, name, path |

## Links

- npm: https://www.npmjs.com/package/query-by-name-path
- Repository: https://github.com/adf0001/query-by-name-path
- Homepage: https://github.com/adf0001/query-by-name-path#readme
- Issues: https://github.com/adf0001/query-by-name-path/issues
- npm.io page: https://npm.io/package/query-by-name-path

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-11-06
- 1.0.0 — 2021-11-06

## README

# query-by-name-path
query dom element by name attribute path

# Install
```
npm install query-by-name-path
```

# Usage & Api
```javascript

var queryByNamePath = require("query-by-name-path");

/*
	namePath:
		array
			name string array;
		string
			name string list separated only by "." ( in priority );
			or name string list separated only by whitespace.
	strict:
		false
			it may have other names from `el` to the end of the name path;
		true
			it shouldn't have any other name from `el` to the end of the name path;
		undefined
			if `namePath` contain '.' then set strict to true, otherwise set to false.
*/
//queryByNamePath(el, namePath, strict)

document.getElementById('divResult3').innerHTML = '\
    <span name=a>aaa</span> \
    <span name=b>bbb \
        <span name=c>ccc</span> \
        <span name=a>aaa2</span> \
        <span name=d>ddd \
            <span>no-name \
                <span name=e>eee</span> \
            </span>\
        </span>\
    </span>\
    <span>no-name \
        <span name=c>ccc2</span> \
    </span>\
    ';

assert(
    queryByNamePath('divResult3', 'a').textContent === 'aaa' &&
    queryByNamePath('divResult3', 'c').textContent === 'ccc' &&
    queryByNamePath('divResult3', 'c', true).textContent === 'ccc2' && 	//strict mode
    queryByNamePath('divResult3', '.c').textContent === 'ccc2' && 	//strict mode
    queryByNamePath('divResult3', 'b.c').textContent === 'ccc' && 	//strict mode
    queryByNamePath('divResult3', ['b', 'c']).textContent === 'ccc' &&
    queryByNamePath('divResult3', ['b', 'a']).textContent === 'aaa2' &&

    queryByNamePath('divResult3', 'e').textContent === 'eee' &&
    queryByNamePath('divResult3', 'd.e', false).textContent === 'eee' &&
    queryByNamePath('divResult3', 'b.e', false).textContent === 'eee' &&
    queryByNamePath('divResult3', 'e', true) === null && 	//strict mode
    queryByNamePath('divResult3', 'd.e') === null && 	//strict mode
    queryByNamePath('divResult3', 'b.e') === null && 	//strict mode
    queryByNamePath('divResult3', 'b.d.e').textContent === 'eee' 	//strict mode
);

```

---
_Source: https://npm.io/package/query-by-name-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
