npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pka_opendynamics_2025/citylens-ngsi-ld

v1.0.0

Published

CityLens - Thư viện xây dựng và xử lý NGSI-LD entities theo chuẩn ETSI

Readme

CityLens NGSI-LD

Thư viện xây dựng và xử lý NGSI-LD entities theo chuẩn ETSI cho nền tảng CityLens Smart City.

Cài đặt

npm install @pka_opendynamics_2025/citylens-ngsi-ld

Sử dụng

Tạo Entity ID

import { createEntityId, parseEntityId, isValidEntityId } from '@pka_opendynamics_2025/citylens-ngsi-ld';

// Tạo URN theo chuẩn NGSI-LD
const id = createEntityId('CivicIssue', '12345');
// => 'urn:ngsi-ld:CivicIssue:12345'

// Phân tích URN
const parsed = parseEntityId(id);
// => { entityType: 'CivicIssue', id: '12345' }

// Kiểm tra URN hợp lệ
console.log(isValidEntityId(id)); // => true

Tạo Properties

import { createProperty, createGeoProperty, createRelationship } from '@pka_opendynamics_2025/citylens-ngsi-ld';

// Property đơn giản
const name = createProperty('Hà Nội');

// Property với thời gian quan sát
const temperature = createProperty(28.5, {
  observedAt: new Date(),
  unitCode: 'CEL',
});

// GeoProperty (vị trí)
const location = createGeoProperty(21.0285, 105.8542);

// Relationship (liên kết)
const refUser = createRelationship('urn:ngsi-ld:User:admin');

Tạo Smart City Entities

import {
  createAirQualityObserved,
  createTrafficFlowObserved,
  createCivicIssue,
} from '@pka_opendynamics_2025/citylens-ngsi-ld';

// Tạo AirQualityObserved entity
const airQuality = createAirQualityObserved({
  id: 'station-001',
  location: { lat: 21.0285, lon: 105.8542 },
  aqi: 75,
  pm25: 45.2,
  pm10: 68.1,
  source: 'AQICN',
});

// Tạo TrafficFlowObserved entity
const traffic = createTrafficFlowObserved({
  id: 'road-001',
  location: { lat: 21.0285, lon: 105.8542 },
  intensity: 450,
  averageSpeed: 35,
  congestionLevel: 'moderate',
});

// Tạo CivicIssue entity (báo cáo công dân)
const issue = createCivicIssue({
  id: 'report-001',
  title: 'Đèn đường hỏng',
  description: 'Đèn đường tại ngã tư không hoạt động',
  location: { lat: 21.0285, lon: 105.8542 },
  category: 'infrastructure',
  priority: 'high',
  reportedBy: 'user123',
});

Validate Entity

import { validateEntity } from '@pka_opendynamics_2025/citylens-ngsi-ld';

const result = validateEntity(entity);
if (!result.valid) {
  console.error('Lỗi:', result.errors);
}

Xây dựng Query

import { buildQueryString } from '@pka_opendynamics_2025/citylens-ngsi-ld';

const query = buildQueryString({
  type: 'AirQualityObserved',
  geoQ: {
    geometry: 'Point',
    coordinates: [105.8542, 21.0285],
    georel: 'near',
    maxDistance: 5000, // 5km
  },
  limit: 10,
});
// => "type=AirQualityObserved&geometry=Point&coordinates=[105.8542,21.0285]&georel=near;maxDistance==5000&limit=10"

API

Entity ID

  • createEntityId(entityType, id) - Tạo URN chuẩn NGSI-LD
  • parseEntityId(urn) - Phân tích URN
  • isValidEntityId(urn) - Kiểm tra URN hợp lệ

Property Builders

  • createProperty(value, options?) - Tạo Property
  • createGeoProperty(lat, lon) - Tạo GeoProperty
  • createRelationship(targetId) - Tạo Relationship

Entity Builders

  • createAirQualityObserved(input) - Tạo AirQualityObserved
  • createTrafficFlowObserved(input) - Tạo TrafficFlowObserved
  • createCivicIssue(input) - Tạo CivicIssue

Validation & Query

  • validateEntity(entity) - Kiểm tra entity hợp lệ
  • buildQueryString(params) - Xây dựng query string

Constants

  • NGSI_LD_CORE_CONTEXT - ETSI Core Context URL
  • SMART_DATA_MODELS_CONTEXT - Smart Data Models Context URL
  • CITYLENS_CONTEXT - CityLens Context URL
  • DEFAULT_CONTEXTS - Mảng contexts mặc định

Kiểu dữ liệu

interface NgsiLdProperty<T> {
  type: 'Property';
  value: T;
  observedAt?: string;
  unitCode?: string;
}

interface NgsiLdGeoProperty {
  type: 'GeoProperty';
  value: { type: 'Point'; coordinates: [number, number] };
}

interface NgsiLdRelationship {
  type: 'Relationship';
  object: string;
}

interface NgsiLdEntity {
  '@context'?: string | string[];
  id: string;
  type: string;
  [key: string]: unknown;
}

Tham khảo

Giấy phép

GPL-3.0