obj-lite 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vkuyxu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # obj-lite
2
+
3
+ A lightweight utility library for object manipulation.
4
+
5
+ ## ## Installation
6
+
7
+ ```bash
8
+ npm install obj-lite
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ import { omit, pick, set, get } from 'obj-lite';
15
+
16
+ // Example usage
17
+ const obj = { a: 1, b: 2, c: { d: 3 } };
18
+
19
+ // Omit properties
20
+ const omitted = omit(obj, ['a']); // { b: 2, c: { d: 3 } }
21
+
22
+ // Pick properties
23
+ const picked = pick(obj, ['a', 'c']); // { a: 1, c: { d: 3 } }
24
+
25
+ // Set property
26
+ const newObj = set({}, 'a.b.c', 1); // { a: { b: { c: 1 } } }
27
+
28
+ // Get property
29
+ const value = get(obj, 'c.d'); // 3
30
+ ```
31
+
32
+
33
+ ## API
34
+
35
+
36
+ * `omit(object, paths)` - Remove specified properties from object
37
+ * `pick(object, paths)` - Select specified properties from object
38
+ * `set(object, path, value)` - Set value at specified path
39
+ * `get(object, path, defaultValue)` - Get value at specified path
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ function r(r){return function(r,n){return Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,value:o(n),writable:!0})}(function(r,n,t){return n=e(void 0===n?r.length-1:n,0),function(){for(var u=arguments,o=-1,f=e(u.length-n,0),i=Array(f);++o<f;)i[o]=u[n+o];o=-1;for(var a=Array(n+1);++o<n;)a[o]=u[o];return a[n]=t(i),r.apply(this,a)}}(r,void 0,n),r+"")}function n(r){return(null==r?0:r.length)?t(r,1):[]}function t(r,n,o,e,f){if(o||(o=u),f||(f=[]),null==r)return f;for(var i=0,a=r.length;a>i;i++){var c=r[i];if(n>0&&o(c))if(n>1)t(c,n-1,o,e,f);else for(var l=f.length,v=0,y=c.length;y>v;v++)f[l+v]=c[v];else e||(f[f.length]=c)}return f}function u(r){return Array.isArray(r)||"object"==typeof r&&null!=r&&r.constructor===Array&&"function"==typeof r.splice}function o(r){return function(){return r}}var e=Math.max;function f(r,n){for(var t=-1,u=null==r?0:r.length,o=Array(u);++t<u;)o[t]=n(r[t],t,r);return o}function i(r,n){if(Array.isArray(r))return r;var t=[];return"string"==typeof r?r.split(".").forEach(function(r){t.push(r)}):t.push(r),t}function a(r,n){Array.isArray(n)||(n=[n]);for(var t=n.length-1,u=r,o=0;t>o;o++){if(null==u)return!0;u=u[n[o]]}var e=n[t];return!(null==u||!s.call(u,e))&&(delete u[e],!0)}function c(r,n){for(var t=0,u=n.length;null!=r&&u>t;)r=r[n[t++]];return t&&t===u?r:void 0}function l(r,n,t,u){if(!y(r))return r;for(var o=-1,e=(n=i(n)).length,f=e-1,a=r;null!=a&&++o<e;){var c=b(n[o]),l=t;if("__proto__"===c||"constructor"===c||"prototype"===c)return r;if(o!=f){var p=a[c];void 0===(l=u?u(p,c,a):void 0)&&(l=y(p)?p:isIndex(n[o+1])?[]:{})}v(a,c,l),a=a[c]}return r}function v(r,n,t){var u=r[n];s.call(r,n)&&function(r,n){return r===n||r!=r&&n!=n}(u,t)&&(void 0!==t||n in r)||function(r,n,t){"__proto__"===n?Object.defineProperty(r,n,{configurable:!0,enumerable:!0,value:t,writable:!0}):r[n]=t}(r,n,t)}function y(r){var n=typeof r;return null!=r&&("object"==n||"function"==n)}function b(r){if("string"==typeof r||function(r){var n=typeof r;return"symbol"===n||"object"===n&&null!=r&&r.toString===Symbol.prototype.toString}(r))return r;var n=r+"";return"0"===n&&1/r===-p?"-0":n}var p=1/0,s=Object.prototype.hasOwnProperty,d=r(function(r,n){var t={},u=!1;if(null==r)return t;n=f(n,function(r){return r=i(r),u||(u=r.length>1),r}),function(r,n,t){for(var u=-1,o=n.length;++u<o;){var e=n[u];t[e]=r[e]}}(r,function(r){var n=[];for(var t in r)n.push(t);return n}(r),t);for(var o=n.length;o--;)a(t,n[o]);return t}),_=r(function(r,n){var t={};if(null==r)return t;n=f(n,function(r){return i(r)});for(var u=-1,o=n.length;++u<o;){var e=n[u],a=c(r,e);void 0!==a&&l(t,e,a)}return t}),A=r(function(r,n,t){return null==r&&(r={}),l(r,n,t)}),j=r(function(r,n,t){if(null==r)return t;var u=c(r,n);return void 0===u?t:u});exports.get=j,exports.omit=d,exports.pick=_,exports.set=A;
2
+ //# sourceMappingURL=index.cjs.map
package/index.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ declare module "obj-lite" {
2
+ /**
3
+ * 从对象中排除指定的属性路径
4
+ */
5
+ export function omit<T extends Record<string, any>>(
6
+ object: T,
7
+ paths: string[],
8
+ ): Partial<T>;
9
+
10
+ /**
11
+ * 从对象中选择指定的属性路径
12
+ */
13
+ export function pick<T extends Record<string, any>, K extends keyof T>(
14
+ object: T,
15
+ paths: K[],
16
+ ): Pick<T, K>;
17
+
18
+ /**
19
+ * 设置对象指定路径的值
20
+ */
21
+ export function set<T extends Record<string, any>>(
22
+ object: T,
23
+ path: string,
24
+ value: any,
25
+ ): T;
26
+
27
+ /**
28
+ * 获取对象指定路径的值
29
+ */
30
+ export function get<T>(
31
+ object: any,
32
+ path: string,
33
+ defaultValue?: T,
34
+ ): T | undefined;
35
+
36
+ const objLite: {
37
+ omit: typeof omit;
38
+ pick: typeof pick;
39
+ set: typeof set;
40
+ get: typeof get;
41
+ };
42
+
43
+ export default objLite;
44
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "obj-lite",
3
+ "version": "0.1.0",
4
+ "description": "Check if a value is an object",
5
+ "license": "MIT",
6
+ "repository": "vkuyxu/lite-obj",
7
+ "author": {
8
+ "name": "vkuyxu",
9
+ "email": "vkuyxu@163.com"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.cjs",
13
+ "files": [
14
+ "dist/index.cjs",
15
+ "index.d.ts",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "engines": {
20
+ "node": ">=12"
21
+ },
22
+ "scripts": {
23
+ "build": "rollup -c"
24
+ },
25
+ "keywords": [
26
+ "object",
27
+ "lite",
28
+ "omit",
29
+ "pick",
30
+ "set",
31
+ "get",
32
+ "utils",
33
+ "utilsity"
34
+ ],
35
+ "devDependencies": {
36
+ "@rollup/plugin-commonjs": "^24.1.0",
37
+ "@rollup/plugin-node-resolve": "^15.0.2",
38
+ "rollup": "^3.21.0",
39
+ "rollup-plugin-terser": "^7.0.2"
40
+ }
41
+ }