neis-school-info 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,12 +52,6 @@ const result = await search(
52
52
  fetch: customFetch, // (선택) 커스텀 fetch 전달
53
53
  },
54
54
  );
55
-
56
- if (result.ok) {
57
- result.schools
58
- // 행정표준코드가 없는 학교를 제외할 수 있음
59
- .filter((school) => school.행정표준코드 !== null);
60
- }
61
55
  ```
62
56
 
63
57
  > [!IMPORTANT]
@@ -88,7 +82,7 @@ type Filters = Partial<{
88
82
  설립명: string; // 예: `공` → `공립` 검색 안 됨
89
83
  시도교육청코드: 시도교육청코드; // 권장
90
84
  시도명: 시도명 | (string & {}); // 지양
91
- 학교종류명: string;
85
+ 학교종류명: 학교종류명 | (string & {});
92
86
  행정표준코드: string | null;
93
87
  }>;
94
88
  ```
@@ -99,6 +93,35 @@ type Filters = Partial<{
99
93
  > [!NOTE]
100
94
  > `시도교육청코드`, `설립명` 등 열거형은 패키지에서 직접 가져올 수 있다. 전체 목록은 [`src/index.ts`](./src/index.ts)를 참고한다.
101
95
 
96
+ ### 좁히기
97
+
98
+ 아래 예제는 필터링 후 타입도 함께 좁혀진다.
99
+
100
+ > [!CAUTION]
101
+ > `result.schools`를 필터링한 배열의 길이는 `result.meta.pageSize`와 다를 수 있다.
102
+
103
+ #### 행정표준코드가 없는 학교 제외
104
+
105
+ ```ts
106
+ if (result.ok) {
107
+ const schools = result.schools.filter((school) => school.행정표준코드 !== null);
108
+ }
109
+ ```
110
+
111
+ #### 여러 학교 종류명으로 필터링
112
+
113
+ `filters.학교종류명`은 나이스 API 제약으로 단일 값만 지원한다.
114
+
115
+ ```ts
116
+ import { filterBy학교종류명, search } from 'neis-school-info';
117
+
118
+ const result = await search({ filters: { 시도명: '서울특별시' } }, { apiKey: 'NEIS_OPEN_API_KEY' });
119
+
120
+ if (result.ok) {
121
+ const schools = filterBy학교종류명(result.schools, ['초등학교', '중학교']);
122
+ }
123
+ ```
124
+
102
125
  ### 응답값
103
126
 
104
127
  이 라이브러리는 나이스 API 응답값을 검증하고 변환한다 (예: `도로명우편번호`는 공백을 제거한 후 5자리 숫자가 아니면 `null`로 변환함).
package/dist/index.d.ts CHANGED
@@ -1,3 +1,30 @@
1
+ import "valibot";
2
+ //#region src/enums/school-value.d.ts
3
+ type 학교종류명 = (typeof 학교종류명)[number];
4
+ declare const 학교종류명: readonly ['초등학교', '중학교', '고등학교', '특수학교', '고등기술학교', '고등공민학교', '공동실습소', '국제학교', '외국인학교', '방송통신중학교', '방송통신고등학교', '각종학교(초)', '각종학교(중)', '각종학교(고)', '각종학교(대안학교)', '각종학교(외국인학교)', '평생학교(초)-3년6학기', '평생학교(초)-4년12학기', '평생학교(중)-2년6학기', '평생학교(중)-3년6학기', '평생학교(고)-2년6학기', '평생학교(고)-3년6학기', '재외한국학교(초)', '재외한국학교(중)', '재외한국학교(고)'];
5
+ export type 고등학교구분명 = (typeof 고등학교구분명)[number];
6
+ export declare const 고등학교구분명: readonly ['일반고', '특성화고', '자율고', '특목고'];
7
+ export type 고등학교일반전문구분명 = (typeof 고등학교일반전문구분명)[number];
8
+ export declare const 고등학교일반전문구분명: readonly ['해당없음', '일반계', '전문계'];
9
+ export type 남녀공학구분명 = (typeof 남녀공학구분명)[number];
10
+ export declare const 남녀공학구분명: readonly ['남여공학', '남', '여'];
11
+ export type 설립명 = (typeof 설립명)[number];
12
+ export declare const 설립명: readonly ['공립', '사립', '국립', '기타', '국외'];
13
+ export type 입시전후기구분명 = (typeof 입시전후기구분명)[number];
14
+ export declare const 입시전후기구분명: readonly ['전기', '후기', '전후기'];
15
+ export type 주야구분명 = (typeof 주야구분명)[number];
16
+ export declare const 주야구분명: readonly ['주간', '야간', '주야간'];
17
+ type YN = (typeof YN_VALUES)[number];
18
+ declare const YN_VALUES: readonly ['Y', 'N'];
19
+ //#endregion
20
+ //#region src/filter.d.ts
21
+ type SchoolWithKind<S, Kinds extends readonly string[]> = S & {
22
+ 학교종류명: Kinds[number];
23
+ };
24
+ export declare const filterBy학교종류명: <School extends {
25
+ 학교종류명: unknown;
26
+ }, const Kinds extends readonly (학교종류명 | (string & {}))[]>(schools: readonly School[], 학교종류명: Kinds) => SchoolWithKind<School, Kinds>[];
27
+ //#endregion
1
28
  //#region src/enums/office-code.d.ts
2
29
  type 시도명 = (typeof OFFICE_CODE_TO_NAMES)[시도교육청코드][0];
3
30
  declare const OFFICE_CODE_TO_NAMES: {
@@ -23,24 +50,6 @@ declare const OFFICE_CODE_TO_NAMES: {
23
50
  export type 시도교육청코드 = (typeof 시도교육청코드)[number];
24
51
  export declare const 시도교육청코드: readonly ['B10', 'C10', 'D10', 'E10', 'F10', 'G10', 'H10', 'I10', 'J10', 'K10', 'M10', 'N10', 'P10', 'Q10', 'R10', 'S10', 'T10', 'V10'];
25
52
  //#endregion
26
- //#region src/enums/school-value.d.ts
27
- type 학교종류명 = (typeof 학교종류명)[number];
28
- declare const 학교종류명: readonly ['초등학교', '중학교', '고등학교', '특수학교', '고등기술학교', '고등공민학교', '공동실습소', '국제학교', '외국인학교', '방송통신중학교', '방송통신고등학교', '각종학교(초)', '각종학교(중)', '각종학교(고)', '각종학교(대안학교)', '각종학교(외국인학교)', '평생학교(초)-3년6학기', '평생학교(초)-4년12학기', '평생학교(중)-2년6학기', '평생학교(중)-3년6학기', '평생학교(고)-2년6학기', '평생학교(고)-3년6학기', '재외한국학교(초)', '재외한국학교(중)', '재외한국학교(고)'];
29
- export type 고등학교구분명 = (typeof 고등학교구분명)[number];
30
- export declare const 고등학교구분명: readonly ['일반고', '특성화고', '자율고', '특목고'];
31
- export type 고등학교일반전문구분명 = (typeof 고등학교일반전문구분명)[number];
32
- export declare const 고등학교일반전문구분명: readonly ['해당없음', '일반계', '전문계'];
33
- export type 남녀공학구분명 = (typeof 남녀공학구분명)[number];
34
- export declare const 남녀공학구분명: readonly ['남여공학', '남', '여'];
35
- export type 설립명 = (typeof 설립명)[number];
36
- export declare const 설립명: readonly ['공립', '사립', '국립', '기타', '국외'];
37
- export type 입시전후기구분명 = (typeof 입시전후기구분명)[number];
38
- export declare const 입시전후기구분명: readonly ['전기', '후기', '전후기'];
39
- export type 주야구분명 = (typeof 주야구분명)[number];
40
- export declare const 주야구분명: readonly ['주간', '야간', '주야간'];
41
- type YN = (typeof YN_VALUES)[number];
42
- declare const YN_VALUES: readonly ['Y', 'N'];
43
- //#endregion
44
53
  //#region src/valibot.d.ts
45
54
  type School = {
46
55
  시도교육청코드: 시도교육청코드;
@@ -80,7 +89,7 @@ type Filters = Partial<{
80
89
  시도교육청코드: 시도교육청코드;
81
90
  행정표준코드: string | null;
82
91
  학교명: string;
83
- 학교종류명: string;
92
+ 학교종류명: 학교종류명 | (string & {});
84
93
  시도명: 시도명 | (string & {});
85
94
  설립명: string;
86
95
  }>;
package/dist/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  import { array, check, digits, entriesFromList, fallback, integer, isoDate, length, maxLength, maxValue, minLength, minValue, nonEmpty, nullable, number, object, optional, parse, pick, picklist, pipe, safeParse, strictObject, string, transform, trim, tuple, unknown, url } from "valibot";
2
+ //#region src/filter.ts
3
+ const filterBy학교종류명 = (schools, 학교종류명) => {
4
+ const kindSet = new Set(학교종류명);
5
+ return schools.filter((school) => kindSet.has(school.학교종류명));
6
+ };
7
+ //#endregion
2
8
  //#region src/enums/filter-key.ts
3
9
  const FILTER_KEY_TO_SEARCH = {
4
10
  시도교육청코드: "ATPT_OFCDC_SC_CODE",
@@ -215,4 +221,4 @@ const search = async (params, opts) => {
215
221
  };
216
222
  };
217
223
  //#endregion
218
- export { search, 고등학교구분명, 고등학교일반전문구분명, 남녀공학구분명, 설립명, 시도교육청코드, 입시전후기구분명, 주야구분명 };
224
+ export { filterBy학교종류명, search, 고등학교구분명, 고등학교일반전문구분명, 남녀공학구분명, 설립명, 시도교육청코드, 입시전후기구분명, 주야구분명 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neis-school-info",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "대한민국 학교 기본 정보 조회 (나이스 Open API 기반)",
5
5
  "homepage": "https://github.com/hyunbinseo/neis-school-info#readme",
6
6
  "bugs": {
@@ -29,11 +29,11 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "valibot": "^1.4.2"
32
+ "valibot": "^1.5.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@arethetypeswrong/core": "^0.18.5",
36
- "@types/node": "^24.13.3",
36
+ "@types/node": "^24.13.4",
37
37
  "markdown-table": "^3.0.4",
38
38
  "oxfmt": "^0.67.0",
39
39
  "oxlint": "^1.82.0",
@@ -45,7 +45,7 @@
45
45
  "devEngines": {
46
46
  "packageManager": {
47
47
  "name": "pnpm",
48
- "version": "12.4.0",
48
+ "version": "12.4.1",
49
49
  "onFail": "download"
50
50
  },
51
51
  "runtime": {